1<?php
2/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4include_once("./Services/Table/classes/class.ilTable2GUI.php");
5
6/**
7* TableGUI class for
8*
9* @author Alex Killing <alex.killing@gmx.de>
10* @version $Id$
11*
12* @ingroup ServicesUser
13*/
14class ilUserFieldSettingsTableGUI extends ilTable2GUI
15{
16    private $confirm_change = false;
17
18    /**
19     * @var ilUserSettingsConfig
20     */
21    protected $user_settings_config;
22
23    /**
24    * Constructor
25    */
26    public function __construct($a_parent_obj, $a_parent_cmd)
27    {
28        global $DIC;
29
30        $ilCtrl = $DIC['ilCtrl'];
31        $lng = $DIC['lng'];
32        $ilAccess = $DIC['ilAccess'];
33        $lng = $DIC['lng'];
34
35        $this->user_settings_config = new ilUserSettingsConfig();
36
37        parent::__construct($a_parent_obj, $a_parent_cmd);
38        $this->setTitle($lng->txt("usr_settings_header_profile"));
39        $this->setDescription($lng->txt("usr_settings_explanation_profile"));
40        $this->setLimit(9999);
41
42        //$this->addColumn($this->lng->txt("usrs_group"), "");
43        //$this->addColumn("", "");
44        $this->addColumn($this->lng->txt("user_field"), "");
45        $this->addColumn($this->lng->txt("access"), "");
46        $this->addColumn($this->lng->txt("export") . " / " . $this->lng->txt("search"), "");
47        $this->addColumn($this->lng->txt("default"), "");
48
49        $this->setEnableHeader(true);
50        $this->setFormAction($ilCtrl->getFormAction($a_parent_obj));
51        $this->setRowTemplate("tpl.std_fields_settings_row.html", "Services/User");
52        $this->disable("footer");
53        $this->setEnableTitle(true);
54
55        include_once("./Services/User/classes/class.ilUserProfile.php");
56        $up = new ilUserProfile();
57        $up->skipField("username");
58        $fds = $up->getStandardFields();
59        // vd($fds);
60        foreach ($fds as $k => $f) {
61            $fds[$k]["key"] = $k;
62        }
63        $this->setData($fds);
64        $this->addCommandButton("saveGlobalUserSettings", $lng->txt("save"));
65    }
66
67    /**
68    * Fill table row
69    */
70    protected function fillRow($a_set)
71    {
72        global $DIC;
73
74        $lng = $DIC['lng'];
75        $ilSetting = $DIC['ilSetting'];
76        $user_settings_config = $this->user_settings_config;
77
78        $field = $a_set["key"];
79
80        $props = array(
81            "visible" => "user_visible_in_profile",
82            "changeable" => "changeable",
83            "searchable" => "header_searchable",
84            "required" => "required_field",
85            "export" => "export",
86            "course_export" => "course_export",
87            'group_export' => 'group_export',
88            "visib_reg" => "header_visible_registration",
89            'visib_lua' => 'usr_settings_visib_lua',
90            'changeable_lua' => 'usr_settings_changeable_lua'
91        );
92
93        foreach ($props as $prop => $lv) {
94            $up_prop = strtoupper($prop);
95
96            if (($prop != "searchable" && $a_set[$prop . "_hide"] != true) ||
97                ($prop == "searchable" && ilUserSearchOptions::_isSearchable($field))) {
98                $this->tpl->setCurrentBlock($prop);
99                $this->tpl->setVariable(
100                    "HEADER_" . $up_prop,
101                    $lng->txt($lv)
102                );
103                $this->tpl->setVariable("PROFILE_OPTION_" . $up_prop, $prop . "_" . $field);
104
105                // determine checked status
106                $checked = false;
107                if ($prop == "visible" && $user_settings_config->isVisible($field)) {
108                    $checked = true;
109                }
110                if ($prop == "changeable" && $user_settings_config->isChangeable($field)) {
111                    $checked = true;
112                }
113                if ($prop == "searchable" && ilUserSearchOptions::_isEnabled($field)) {
114                    $checked = true;
115                }
116                if ($prop == "required" && $ilSetting->get("require_" . $field) == "1") {
117                    $checked = true;
118                }
119                if ($prop == "export" && $ilSetting->get("usr_settings_export_" . $field) == "1") {
120                    $checked = true;
121                }
122                if ($prop == "course_export" && $ilSetting->get("usr_settings_course_export_" . $field) == "1") {
123                    $checked = true;
124                }
125                if ($prop == "group_export" && $ilSetting->get("usr_settings_group_export_" . $field) == "1") {
126                    $checked = true;
127                }
128                if ($prop == "visib_reg" && (int) $ilSetting->get('usr_settings_visib_reg_' . $field, '1')) {
129                    $checked = true;
130                }
131                if ($prop == "visib_lua" && (int) $ilSetting->get('usr_settings_visib_lua_' . $field, '1')) {
132                    $checked = true;
133                }
134
135                if ($prop == "changeable_lua" && (int) $ilSetting->get('usr_settings_changeable_lua_' . $field, '1')) {
136                    $checked = true;
137                }
138
139
140                if ($this->confirm_change == 1) {	// confirm value
141                    $checked = $_POST["chb"][$prop . "_" . $field];
142                }
143                if (isset($a_set[$prop . "_fix_value"])) {	// fix values overwrite everything
144                    $checked = $a_set[$prop . "_fix_value"];
145                }
146
147                if ($checked) {
148                    $this->tpl->setVariable("CHECKED_" . $up_prop, " checked=\"checked\"");
149                }
150                if (isset($a_set[$prop . "_fix_value"])) {
151                    $this->tpl->setVariable("DISABLE_" . $up_prop, " disabled=\"disabled\"");
152                }
153                $this->tpl->parseCurrentBlock();
154            }
155        }
156
157        // default
158        if ($a_set["default"] != "") {
159            switch ($a_set["input"]) {
160                case "selection":
161                case "hitsperpage":
162                    $selected_option = $ilSetting->get($field);
163                    if ($selected_option == "") {
164                        $selected_option = $a_set["default"];
165                    }
166                    foreach ($a_set["options"] as $k => $v) {
167                        $this->tpl->setCurrentBlock("def_sel_option");
168                        $this->tpl->setVariable("OPTION_VALUE", $k);
169                        $text = ($a_set["input"] == "selection")
170                            ? $lng->txt($v)
171                            : $v;
172                        if ($a_set["input"] == "hitsperpage" && $k == 9999) {
173                            $text = $lng->txt("no_limit");
174                        }
175                        if ($selected_option == $k) {
176                            $this->tpl->setVariable(
177                                "OPTION_SELECTED",
178                                ' selected="selected" '
179                            );
180                        }
181                        $this->tpl->setVariable("OPTION_TEXT", $text);
182                        $this->tpl->parseCurrentBlock();
183                    }
184                    $this->tpl->setCurrentBlock("def_selection");
185                    $this->tpl->setVariable("PROFILE_OPTION_DEFAULT_VALUE", "default_" . $field);
186                    $this->tpl->parseCurrentBlock();
187                    break;
188            }
189            $this->tpl->setCurrentBlock("default");
190            $this->tpl->parseCurrentBlock();
191        }
192
193        // group name
194        $this->tpl->setVariable("TXT_GROUP", $lng->txt($a_set["group"]));
195
196        // field name
197        $lv = ($a_set["lang_var"] == "")
198            ? $a_set["key"]
199            : $a_set["lang_var"];
200        if ($a_set["key"] == "country") {
201            $lv = "country_free_text";
202        }
203        if ($a_set["key"] == "sel_country") {
204            $lv = "country_selection";
205        }
206
207        $this->tpl->setVariable("TXT_FIELD", $lng->txt($lv));
208    }
209
210    public function setConfirmChange()
211    {
212        $this->confirm_change = true;
213    }
214}
215