1<?php
2
3/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
4
5/**
6 * Config class for page editing
7 *
8 * @author Alex Killing <alex.killing.gmx.de>
9 * @version $Id$
10 * @ingroup ServicesCOPage
11 */
12abstract class ilPageConfig
13{
14    /**
15     * @var ilLanguage
16     */
17    protected $lng;
18
19    protected $int_link_filter = array("File", "PortfolioPage", "PortfolioTemplatePage");
20    protected $prevent_rte_usage = false;
21    protected $use_attached_content = false;
22    protected $pc_defs = array();
23    protected $pc_enabled = array();
24    protected $enabledinternallinks = false;
25    protected $enable_keywords = false;
26    protected $enable_anchors = false;
27    protected $enablewikilinks = false;
28    protected $page_toc = false;
29    protected $activation = false;
30    protected $scheduled_activation = false;
31    protected $preventhtmlunmasking = false;
32    protected $enabledselfassessment = false;
33    protected $enabledselfassessment_scorm = false;
34    protected $int_link_def_type = "";
35    protected $int_link_def_id = 0;
36    protected $multi_lang_support = false;
37    protected $single_page_mode = false;	// currently only used by multi-lang support
38    // single page means: only one page per parent_id
39    protected $disable_default_qfeedback = false;
40    protected $question_html = array();
41    protected $use_stored_tries = false;
42    protected $enable_user_links = false;
43
44    protected $edit_lock_support = true;
45
46    /**
47     * @var bool
48     */
49    protected $enable_permission_checks = false;
50
51    /**
52     * @var \ilSetting
53     */
54    protected $adve_set;
55
56    /**
57     * Key as returned by ilCOPageObjDef->getDefinitions()
58     * @var string
59     */
60    protected $page_obj_key = "";
61
62    /**
63     * Constructor
64     *
65     * @param
66     */
67    final public function __construct()
68    {
69        global $DIC;
70
71        $this->lng = $DIC->language();
72        // load pc_defs
73        include_once("./Services/COPage/classes/class.ilCOPagePCDef.php");
74        $this->pc_defs = ilCOPagePCDef::getPCDefinitions();
75        foreach ($this->pc_defs as $def) {
76            $this->setEnablePCType($def["name"], (bool) $def["def_enabled"]);
77        }
78
79        $this->adve_set = new ilSetting("adve");
80
81        $def = new ilCOPageObjDef();
82        foreach ($def->getDefinitions() as $key => $def) {
83            if (strtolower(get_class($this)) == strtolower($def["class_name"] . "Config")) {
84                $this->page_obj_key = $key;
85            }
86        }
87
88
89        $this->init();
90    }
91
92    /**
93     * Init
94     *
95     * @param
96     * @return
97     */
98    public function init()
99    {
100    }
101
102
103    /**
104     * Set enable pc type
105     *
106     * @param boolean $a_val enable pc type true/false
107     */
108    public function setEnablePCType($a_pc_type, $a_val)
109    {
110        $this->pc_enabled[$a_pc_type] = $a_val;
111    }
112
113    /**
114     * Get enable pc type
115     *
116     * @return boolean enable pc type true/false
117     */
118    public function getEnablePCType($a_pc_type)
119    {
120        return $this->pc_enabled[$a_pc_type];
121    }
122
123    /**
124     * Set enable keywords handling
125     *
126     * @param	boolean	keywords handling
127     */
128    public function setEnableKeywords($a_val)
129    {
130        $this->enable_keywords = $a_val;
131    }
132
133    /**
134     * Get enable keywords handling
135     *
136     * @return	boolean	keywords handling
137     */
138    public function getEnableKeywords()
139    {
140        return $this->enable_keywords;
141    }
142
143    /**
144     * Set enable anchors
145     *
146     * @param	boolean	anchors
147     */
148    public function setEnableAnchors($a_val)
149    {
150        $this->enable_anchors = $a_val;
151    }
152
153    /**
154     * Get enable anchors
155     *
156     * @return	boolean	anchors
157     */
158    public function getEnableAnchors()
159    {
160        return $this->enable_anchors;
161    }
162
163    /**
164     * Set Enable internal links.
165     *
166     * @param	boolean	$a_enabledinternallinks	Enable internal links
167     */
168    public function setEnableInternalLinks($a_enabledinternallinks)
169    {
170        $this->enabledinternallinks = $a_enabledinternallinks;
171    }
172
173    /**
174     * Get Enable internal links.
175     *
176     * @return	boolean	Enable internal links
177     */
178    public function getEnableInternalLinks()
179    {
180        return $this->enabledinternallinks;
181    }
182
183    /**
184     * Get enable user links
185     *
186     * @return boolean enable user links
187     */
188    public function getEnableUserLinks()
189    {
190        if (!$this->getEnableInternalLinks()) {
191            return false;
192        }
193        if ($this->getIntLinkFilterWhiteList() && in_array("User", $this->int_link_filter)) {
194            return true;
195        }
196        if (!$this->getIntLinkFilterWhiteList() && !in_array("User", $this->int_link_filter)) {
197            return true;
198        }
199
200        return false;
201    }
202
203    /**
204     * Set Enable Wiki Links.
205     *
206     * @param	boolean	$a_enablewikilinks	Enable Wiki Links
207     */
208    public function setEnableWikiLinks($a_enablewikilinks)
209    {
210        $this->enablewikilinks = $a_enablewikilinks;
211    }
212
213    /**
214     * Get Enable Wiki Links.
215     *
216     * @return	boolean	Enable Wiki Links
217     */
218    public function getEnableWikiLinks()
219    {
220        return $this->enablewikilinks;
221    }
222
223    /**
224     * Add internal links filter
225     *
226     * @param	string	internal links filter
227     */
228    public function addIntLinkFilter($a_val)
229    {
230        $lng = $this->lng;
231
232        $this->setLocalizationLanguage($lng->getLangKey());
233        if (is_array($a_val)) {
234            $this->int_link_filter =
235                array_merge($a_val, $this->int_link_filter);
236        } else {
237            $this->int_link_filter[] = $a_val;
238        }
239    }
240
241    /**
242     * Remove int link filter
243     *
244     * @param string $a_val internal link filter
245     */
246    public function removeIntLinkFilter($a_val)
247    {
248        foreach ($this->int_link_filter as $k => $v) {
249            if ($v == $a_val) {
250                unset($this->int_link_filter[$k]);
251            }
252        }
253    }
254
255
256    /**
257     * Get internal links filter
258     *
259     * @return	string	internal links filter
260     */
261    public function getIntLinkFilters()
262    {
263        return $this->int_link_filter;
264    }
265
266    /**
267     * Set internal links filter type list to white list
268     *
269     * @param	boolean white list
270     */
271    public function setIntLinkFilterWhiteList($a_white_list)
272    {
273        $this->link_filter_white_list = $a_white_list;
274        if ($a_white_list) {
275            $this->int_link_filter = array();
276        }
277    }
278
279    /**
280     * Get internal links filter type list to white list
281     *
282     * @return	boolean white list
283     */
284    public function getIntLinkFilterWhiteList()
285    {
286        return $this->link_filter_white_list;
287    }
288
289    /**
290     * Set prevent rte usage
291     *
292     * @param	boolean	prevent rte usage
293     */
294    public function setPreventRteUsage($a_val)
295    {
296        $this->prevent_rte_usage = $a_val;
297    }
298
299    /**
300     * Get prevent rte usage
301     *
302     * @return	boolean	prevent rte usage
303     */
304    public function getPreventRteUsage()
305    {
306        return $this->prevent_rte_usage;
307    }
308
309    /**
310     * Set localizazion language
311     *
312     * @param string $a_val lang key
313     */
314    public function setLocalizationLanguage($a_val)
315    {
316        $this->localization_lang = $a_val;
317    }
318
319    /**
320     * Get localizazion language
321     *
322     * @return string lang key
323     */
324    public function getLocalizationLanguage()
325    {
326        return $this->localization_lang;
327    }
328
329    /**
330     * Set use attached content
331     *
332     * @param string $a_val use initial attached content
333     */
334    public function setUseAttachedContent($a_val)
335    {
336        $this->use_attached_content = $a_val;
337    }
338
339    /**
340     * Get use attached content
341     *
342     * @return string use initial attached content
343     */
344    public function getUseAttachedContent()
345    {
346        return $this->use_attached_content;
347    }
348
349    /**
350     * Set internal link default type
351     *
352     * @param string $a_val type
353     */
354    public function setIntLinkHelpDefaultType($a_val)
355    {
356        $this->int_link_def_type = $a_val;
357    }
358
359    /**
360     * Get internal link default type
361     *
362     * @return string type
363     */
364    public function getIntLinkHelpDefaultType()
365    {
366        return $this->int_link_def_type;
367    }
368
369    /**
370     * Set internal link default id
371     *
372     * @param int $a_val default object if
373     */
374    public function setIntLinkHelpDefaultId($a_val, $a_is_ref = true)
375    {
376        $this->int_link_def_id = $a_val;
377        $this->int_link_def_id_is_ref = $a_is_ref;
378    }
379
380    /**
381     * Get internal link default id
382     *
383     * @return int default object if
384     */
385    public function getIntLinkHelpDefaultId()
386    {
387        return $this->int_link_def_id;
388    }
389
390    /**
391     * Get internal link default id
392     *
393     * @return int default object if
394     */
395    public function getIntLinkHelpDefaultIdIsRef()
396    {
397        return $this->int_link_def_id_is_ref;
398    }
399
400    /**
401     * Set enabled actication
402     *
403     * @param bool $a_val page activation enabled?
404     */
405    public function setEnableActivation($a_val)
406    {
407        $this->activation = $a_val;
408    }
409
410    /**
411     * Get enabled actication
412     *
413     * @return bool page activation enabled?
414     */
415    public function getEnableActivation()
416    {
417        return $this->activation;
418    }
419
420    /**
421     * Set enable scheduled page activation
422     *
423     * @param bool $a_val scheduled activated enabled?
424     */
425    public function setEnableScheduledActivation($a_val)
426    {
427        $this->scheduled_activation = $a_val;
428    }
429
430    /**
431     * Get enable scheduled page activation
432     *
433     * @return bool scheduled activated enabled?
434     */
435    public function getEnableScheduledActivation()
436    {
437        return $this->scheduled_activation;
438    }
439
440    /**
441     * Set enable page toc
442     *
443     * @param bool $a_val enable page toc?
444     */
445    public function setEnablePageToc($a_val)
446    {
447        $this->page_toc = $a_val;
448    }
449
450    /**
451     * Get enable page toc
452     *
453     * @return bool enable page toc?
454     */
455    public function getEnablePageToc()
456    {
457        return $this->page_toc;
458    }
459
460    /**
461     * Set Prevent HTML Unmasking (true/false).
462     *
463     * @param	boolean	$a_preventhtmlunmasking	Prevent HTML Unmasking (true/false)
464     */
465    public function setPreventHTMLUnmasking($a_preventhtmlunmasking)
466    {
467        $this->preventhtmlunmasking = $a_preventhtmlunmasking;
468    }
469
470    /**
471    * Get Prevent HTML Unmasking (true/false).
472    *
473    * @return	boolean	Prevent HTML Unmasking (true/false)
474    */
475    public function getPreventHTMLUnmasking()
476    {
477        $safe = true;
478        if ($this->adve_set->get("act_html_" . $this->page_obj_key)) {
479            $safe = false;
480        }
481        return $safe;
482        //return $this->preventhtmlunmasking;
483    }
484
485    /**
486     * Set Enable Self Assessment Questions.
487     *
488     * @param	boolean	$a_enabledselfassessment	Enable Self Assessment Questions
489     */
490    public function setEnableSelfAssessment($a_enabledselfassessment, $a_scorm = true)
491    {
492        $this->setEnablePCType("Question", (bool) $a_enabledselfassessment);
493        $this->enabledselfassessment = $a_enabledselfassessment;
494        $this->enabledselfassessment_scorm = $a_scorm;
495    }
496
497
498    /**
499     * Get Enable Self Assessment Questions.
500     *
501     * @return	boolean	Enable Self Assessment Questions
502     */
503    public function getEnableSelfAssessment()
504    {
505        return $this->enabledselfassessment;
506    }
507
508    /**
509     * Is self assessment used in SCORM mode?
510     *
511     * @return	boolean	Enable Self Assessment Questions
512     */
513    public function getEnableSelfAssessmentScorm()
514    {
515        return $this->enabledselfassessment_scorm;
516    }
517
518    /**
519     * Set disable default question feedback
520     *
521     * @param bool $a_val disable feedback
522     */
523    public function setDisableDefaultQuestionFeedback($a_val)
524    {
525        $this->disable_default_qfeedback = $a_val;
526    }
527
528    /**
529     * Get disable default question feedback
530     *
531     * @return bool disable feedback
532     */
533    public function getDisableDefaultQuestionFeedback()
534    {
535        return $this->disable_default_qfeedback;
536    }
537
538    /**
539     * Set multi language support
540     *
541     * @param bool $a_val general multi language support?
542     */
543    public function setMultiLangSupport($a_val)
544    {
545        $this->multi_lang_support = $a_val;
546    }
547
548    /**
549     * Get multi language support
550     *
551     * @return bool general multi language support?
552     */
553    public function getMultiLangSupport()
554    {
555        return $this->multi_lang_support;
556    }
557
558    /**
559     * Set single page mode
560     *
561     * @param bool $a_val single page mode (only one page per parent_id)
562     */
563    public function setSinglePageMode($a_val)
564    {
565        $this->single_page_mode = $a_val;
566    }
567
568    /**
569     * Get single page mode
570     *
571     * @return bool single page mode (only one page per parent_id)
572     */
573    public function getSinglePageMode()
574    {
575        return $this->single_page_mode;
576    }
577
578    public function setQuestionHTML($question_html)
579    {
580        $this->question_html = $question_html;
581    }
582
583    public function getQuestionHTML()
584    {
585        return $this->question_html;
586    }
587
588    /**
589     * Set use stored answers/tries
590     *
591     * @param bool $a_val use stored number of tries and given (correct) answers
592     */
593    public function setUseStoredQuestionTries($a_val)
594    {
595        $this->use_stored_tries = $a_val;
596    }
597
598    /**
599     * Get use stored answers/tries
600     *
601     * @return bool use stored number of tries and given (correct) answers
602     */
603    public function getUseStoredQuestionTries()
604    {
605        return $this->use_stored_tries;
606    }
607
608    /**
609     * Set enable permission checks
610     *
611     * @param bool $a_val enable permission checks
612     */
613    public function setEnablePermissionChecks($a_val)
614    {
615        $this->enable_permission_checks = $a_val;
616    }
617
618    /**
619     * Get enable permission checks
620     *
621     * @return bool enable permission checks
622     */
623    public function getEnablePermissionChecks()
624    {
625        return $this->enable_permission_checks;
626    }
627
628    /**
629     * @param $a_val  bool set edit lock support for blogs
630     */
631    public function setEditLockSupport($a_val)
632    {
633        $this->edit_lock_support = $a_val;
634    }
635
636    /**
637     * @return bool get edit lock support for blogs
638     */
639    public function getEditLockSupport()
640    {
641        return $this->edit_lock_support;
642    }
643}
644