ILIAS  Release_4_2_x_branch Revision 61807
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilPCProfileGUI.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
24 require_once("./Services/COPage/classes/class.ilPCProfile.php");
25 require_once("./Services/COPage/classes/class.ilPageContentGUI.php");
26 
38 {
39 
44  function ilPCProfileGUI(&$a_pg_obj, &$a_content_obj, $a_hier_id, $a_pc_id = "")
45  {
46  parent::ilPageContentGUI($a_pg_obj, $a_content_obj, $a_hier_id, $a_pc_id);
47  }
48 
52  function &executeCommand()
53  {
54  // get next class that processes or forwards current command
55  $next_class = $this->ctrl->getNextClass($this);
56 
57  // get current command
58  $cmd = $this->ctrl->getCmd();
59 
60  switch($next_class)
61  {
62  default:
63  $ret =& $this->$cmd();
64  break;
65  }
66 
67  return $ret;
68  }
69 
75  function insert(ilPropertyFormGUI $a_form = null)
76  {
77  global $tpl;
78 
79  $this->displayValidationError();
80 
81  if(!$a_form)
82  {
83  $a_form = $this->initForm(true);
84  }
85  $tpl->setContent($a_form->getHTML());
86  }
87 
93  function edit(ilPropertyFormGUI $a_form = null)
94  {
95  global $tpl;
96 
97  $this->displayValidationError();
98 
99  if(!$a_form)
100  {
101  $a_form = $this->initForm();
102  }
103  $tpl->setContent($a_form->getHTML());
104  }
105 
112  protected function initForm($a_insert = false)
113  {
114  global $ilCtrl, $ilToolbar;
115 
116  $ilToolbar->addButton($this->lng->txt("cont_edit_personal_data"),
117  $ilCtrl->getLinkTargetByClass("ilpersonaldesktopgui", "jumptoprofile"),
118  "profile");
119 
120  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
121  $form = new ilPropertyFormGUI();
122  $form->setFormAction($ilCtrl->getFormAction($this));
123  if ($a_insert)
124  {
125  $form->setTitle($this->lng->txt("cont_insert_profile"));
126  }
127  else
128  {
129  $form->setTitle($this->lng->txt("cont_update_profile"));
130  }
131 
132  $mode = new ilRadioGroupInputGUI($this->lng->txt("cont_profile_mode"), "mode");
133  $form->addItem($mode);
134 
135  $mode_inherit = new ilRadioOption($this->lng->txt("cont_profile_mode_inherit"), "inherit");
136  $mode_inherit->setInfo($this->lng->txt("cont_profile_mode_inherit_info"));
137  $mode->addOption($mode_inherit);
138 
139  $mode_manual = new ilRadioOption($this->lng->txt("cont_profile_mode_manual"), "manual");
140  $mode_manual->setInfo($this->lng->txt("cont_profile_mode_manual_info"));
141  $mode->addOption($mode_manual);
142 
143  $prefs = array();
144  if ($a_insert)
145  {
146  $mode->setValue("inherit");
147  }
148  else
149  {
150  $mode_value = $this->content_obj->getMode();
151  $mode->setValue($mode_value);
152 
153  $prefs = array();
154  if($mode_value == "manual")
155  {
156  foreach($this->content_obj->getFields() as $name)
157  {
158  $prefs["public_".$name] = "y";
159  }
160  }
161  }
162 
163  // always has to be set
164  $im_arr = array("icq","yahoo","msn","aim","skype","jabber","voip");
165  foreach ($im_arr as $im)
166  {
167  if(!isset($prefs["public_im_".$im]))
168  {
169  $prefs["public_im_".$im] = "n";
170  }
171  }
172 
173  include_once "Services/User/classes/class.ilPersonalProfileGUI.php";
174  $profile = new ilPersonalProfileGUI();
175  $profile->showPublicProfileFields($form, $prefs, $mode_manual);
176 
177  if ($a_insert)
178  {
179 
180  $form->addCommandButton("create_profile", $this->lng->txt("save"));
181  $form->addCommandButton("cancelCreate", $this->lng->txt("cancel"));
182  }
183  else
184  {
185 
186  $form->addCommandButton("update", $this->lng->txt("save"));
187  $form->addCommandButton("cancelUpdate", $this->lng->txt("cancel"));
188  }
189 
190  return $form;
191  }
192 
198  protected function getFieldsValues()
199  {
200  $fields = array();
201  foreach($_POST as $name => $value)
202  {
203  if(substr($name, 0, 4) == "chk_")
204  {
205  if($value)
206  {
207  $fields[] = substr($name, 4);
208  }
209  }
210  }
211  return $fields;
212  }
213 
217  function create()
218  {
219  $form = $this->initForm(true);
220  if($form->checkInput())
221  {
222  $this->content_obj = new ilPCProfile($this->dom);
223  $this->content_obj->create($this->pg_obj, $this->hier_id, $this->pc_id);
224  $this->content_obj->setFields($form->getInput("mode"),
225  $this->getFieldsValues());
226  $this->updated = $this->pg_obj->update();
227  if ($this->updated === true)
228  {
229  $this->ctrl->returnToParent($this, "jump".$this->hier_id);
230  }
231  }
232 
233  $this->insert($form);
234  }
235 
239  function update()
240  {
241  $form = $this->initForm(true);
242  if($form->checkInput())
243  {
244  $this->content_obj->setFields($form->getInput("mode"),
245  $this->getFieldsValues());
246  $this->updated = $this->pg_obj->update();
247  if ($this->updated === true)
248  {
249  $this->ctrl->returnToParent($this, "jump".$this->hier_id);
250  }
251  }
252 
253  $this->pg_obj->addHierIDs();
254  $this->edit($form);
255  }
256 }
257 
258 ?>