ILIAS  Release_5_0_x_branch Revision 61816
 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  $is_template = ($this->getPageConfig()->getEnablePCType("PlaceHolder"));
117 
118  if(!$is_template)
119  {
120  $ilToolbar->addButton($this->lng->txt("cont_edit_personal_data"),
121  $ilCtrl->getLinkTargetByClass("ilpersonaldesktopgui", "jumptoprofile"),
122  "profile");
123 
124  $lng_suffix = "";
125  }
126  else
127  {
128  $lng_suffix = "_template";
129  }
130 
131  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
132  $form = new ilPropertyFormGUI();
133  $form->setFormAction($ilCtrl->getFormAction($this));
134  if ($a_insert)
135  {
136  $form->setTitle($this->lng->txt("cont_insert_profile"));
137  }
138  else
139  {
140  $form->setTitle($this->lng->txt("cont_update_profile"));
141  }
142 
143  $mode = new ilRadioGroupInputGUI($this->lng->txt("cont_profile_mode"), "mode");
144  $form->addItem($mode);
145 
146  $mode_inherit = new ilRadioOption($this->lng->txt("cont_profile_mode_inherit"), "inherit");
147  $mode_inherit->setInfo($this->lng->txt("cont_profile_mode".$lng_suffix."_inherit_info"));
148  $mode->addOption($mode_inherit);
149 
150  $mode_manual = new ilRadioOption($this->lng->txt("cont_profile_mode_manual"), "manual");
151  $mode_manual->setInfo($this->lng->txt("cont_profile_mode_manual_info"));
152  $mode->addOption($mode_manual);
153 
154  $prefs = array();
155  if ($a_insert)
156  {
157  $mode->setValue("inherit");
158  }
159  else
160  {
161  $mode_value = $this->content_obj->getMode();
162  $mode->setValue($mode_value);
163 
164  $prefs = array();
165  if($mode_value == "manual")
166  {
167  foreach($this->content_obj->getFields() as $name)
168  {
169  $prefs["public_".$name] = "y";
170  }
171  }
172  }
173 
174  // always has to be set
175  $im_arr = array("icq","yahoo","msn","aim","skype","jabber","voip");
176  foreach ($im_arr as $im)
177  {
178  if(!isset($prefs["public_im_".$im]))
179  {
180  $prefs["public_im_".$im] = "n";
181  }
182  }
183 
184  include_once "Services/User/classes/class.ilPersonalProfileGUI.php";
185  $profile = new ilPersonalProfileGUI();
186  $profile->showPublicProfileFields($form, $prefs, $mode_manual, $is_template);
187 
188  if ($a_insert)
189  {
190 
191  $form->addCommandButton("create_profile", $this->lng->txt("save"));
192  $form->addCommandButton("cancelCreate", $this->lng->txt("cancel"));
193  }
194  else
195  {
196 
197  $form->addCommandButton("update", $this->lng->txt("save"));
198  $form->addCommandButton("cancelUpdate", $this->lng->txt("cancel"));
199  }
200 
201  return $form;
202  }
203 
209  protected function getFieldsValues()
210  {
211  $fields = array();
212  foreach($_POST as $name => $value)
213  {
214  if(substr($name, 0, 4) == "chk_")
215  {
216  if($value)
217  {
218  $fields[] = substr($name, 4);
219  }
220  }
221  }
222  return $fields;
223  }
224 
228  function create()
229  {
230  $form = $this->initForm(true);
231  if($form->checkInput())
232  {
233  $this->content_obj = new ilPCProfile($this->getPage());
234  $this->content_obj->create($this->pg_obj, $this->hier_id, $this->pc_id);
235  $this->content_obj->setFields($form->getInput("mode"),
236  $this->getFieldsValues());
237  $this->updated = $this->pg_obj->update();
238  if ($this->updated === true)
239  {
240  $this->ctrl->returnToParent($this, "jump".$this->hier_id);
241  }
242  }
243 
244  $this->insert($form);
245  }
246 
250  function update()
251  {
252  $form = $this->initForm(true);
253  if($form->checkInput())
254  {
255  $this->content_obj->setFields($form->getInput("mode"),
256  $this->getFieldsValues());
257  $this->updated = $this->pg_obj->update();
258  if ($this->updated === true)
259  {
260  $this->ctrl->returnToParent($this, "jump".$this->hier_id);
261  }
262  }
263 
264  $this->pg_obj->addHierIDs();
265  $this->edit($form);
266  }
267 }
268 
269 ?>