• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

Modules/Course/classes/Export/class.ilCourseUserFieldsGUI.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003         +-----------------------------------------------------------------------------+
00004         | ILIAS open source                                                           |
00005         +-----------------------------------------------------------------------------+
00006         | Copyright (c) 1998-2006 ILIAS open source, University of Cologne            |
00007         |                                                                             |
00008         | This program is free software; you can redistribute it and/or               |
00009         | modify it under the terms of the GNU General Public License                 |
00010         | as published by the Free Software Foundation; either version 2              |
00011         | of the License, or (at your option) any later version.                      |
00012         |                                                                             |
00013         | This program is distributed in the hope that it will be useful,             |
00014         | but WITHOUT ANY WARRANTY; without even the implied warranty of              |
00015         | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               |
00016         | GNU General Public License for more details.                                |
00017         |                                                                             |
00018         | You should have received a copy of the GNU General Public License           |
00019         | along with this program; if not, write to the Free Software                 |
00020         | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. |
00021         +-----------------------------------------------------------------------------+
00022 */
00023 include_once('Modules/Course/classes/Export/class.ilCourseDefinedFieldDefinition.php');
00024 include_once('Modules/Course/classes/class.ilCourseAgreement.php');
00025 
00035 class ilCourseUserFieldsGUI
00036 {
00037         private $lng;
00038         private $tpl;
00039         private $ctrl;
00040         private $tabs_gui;
00041         
00042         private $obj_id;
00043         
00044         private $cdf;
00045         
00053         public function __construct($a_obj_id)
00054         {
00055                 global $lng,$tpl,$ilCtrl,$ilTabs;
00056                 
00057                 $this->lng = $lng;
00058                 $this->lng->loadLanguageModule('ps');
00059                 
00060                 $this->tpl = $tpl;
00061                 $this->ctrl = $ilCtrl;
00062                 $this->tabs_gui = $ilTabs;
00063                 
00064                 $this->obj_id = $a_obj_id;
00065         }
00066         
00073         public function executeCommand()
00074         {
00075                 $cmd = $this->ctrl->getCmd();
00076                 
00077                 switch($next_class = $this->ctrl->getNextClass($this))
00078                 {
00079                         default:
00080                                 if(!$cmd)
00081                                 {
00082                                         $cmd = 'show';
00083                                 }
00084                                 $this->$cmd();
00085                                 break;
00086                 }
00087         }
00088         
00094         public function show()
00095         {
00096                 unset($_SESSION['il_cdf_delete']);
00097                 unset($_SESSION['il_cdf_select_num_values']);
00098                 
00099                 
00100                 $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.user_fields_list.html','Modules/Course');
00101                 
00102                 $this->tpl->setVariable('FORMACTION',$this->ctrl->getFormAction($this));
00103                 $this->tpl->setVariable('TABLE_TITLE',$this->lng->txt('ps_crs_user_fields'));
00104                 $this->tpl->setVariable('HEAD_NAME',$this->lng->txt('ps_cdf_name'));
00105                 $this->tpl->setVariable('HEAD_TYPE',$this->lng->txt('ps_cdf_type'));
00106                 $this->tpl->setVariable('HEAD_REQUIRED',$this->lng->txt('ps_cdf_required'));
00107                 
00108                 $this->tpl->setVariable('ADD',$this->lng->txt('ps_cdf_add_field'));
00109                 $this->tpl->setVariable('LINK_ADD',$this->ctrl->getLinkTarget($this,'fieldSelection'));
00110                 
00111                 
00112                 $fields = ilCourseDefinedFieldDefinition::_getFields($this->obj_id);
00113                 
00114                 if(!count($fields))
00115                 {
00116                         $this->tpl->setCurrentBlock('table_empty');
00117                         $this->tpl->setVariable('EMPTY_TXT',$this->lng->txt('ps_cdf_no_fields'));
00118                         $this->tpl->parseCurrentBlock();
00119                 }
00120                 if(ilCourseAgreement::_hasAgreementsByObjId($this->obj_id))
00121                 {
00122                         $this->tpl->setCurrentBlock('warning_modify');
00123                         $this->tpl->setVariable('TXT_WARNING',$this->lng->txt('ps_cdf_warning_modify'));
00124                         $this->tpl->parseCurrentBlock();
00125                 }
00126                 $counter = 0;
00127                 foreach($fields as $field_obj)
00128                 {
00129                         if($field_obj->getType() == IL_CDF_TYPE_SELECT or 1)
00130                         {
00131                                 $this->tpl->setCurrentBlock('show_edit');
00132                                 
00133                                 $this->ctrl->setParameter($this,'field_id',$field_obj->getId());
00134                                 $this->tpl->setVariable('EDIT_LINK',$this->ctrl->getLinkTarget($this,'editField'));
00135                                 $this->ctrl->clearParameters($this);
00136                                 
00137                                 $this->tpl->setVariable('EDIT',$this->lng->txt('edit'));
00138                                 $this->tpl->parseCurrentBlock();
00139                         }
00140 
00141                         $this->tpl->setCurrentBlock('table_content');
00142                         $this->tpl->setVariable('ROWCOL',ilUtil::switchColor($counter++,'tblrow1','tblrow2'));
00143                         $this->tpl->setVariable('CHECKBOX',ilUtil::formCheckbox(0,'field_id[]',$field_obj->getId()));
00144                         $this->tpl->setVariable('NAME',$field_obj->getName());
00145                         $this->tpl->setVariable('TYPE',$field_obj->getType() == IL_CDF_TYPE_SELECT ?
00146                                                                                         $this->lng->txt('ps_type_select') :
00147                                                                                         $this->lng->txt('ps_type_text'));
00148                         $this->tpl->setVariable('REQUIRED',ilUtil::formCheckbox((int) $field_obj->isRequired(),'required['.$field_obj->getId().']',1));
00149                         $this->tpl->parseCurrentBlock();
00150                 }
00151                 $this->tpl->setVariable("DOWNRIGHT",ilUtil::getImagePath('arrow_downright.gif'));
00152                 $this->tpl->setVariable('BTN_DELETE',$this->lng->txt('delete'));
00153                 
00154                 if(count($fields))
00155                 {
00156                         $this->tpl->setCurrentBlock('show_save');
00157                         $this->tpl->setVariable('BTN_SAVE',$this->lng->txt('save'));
00158                         $this->tpl->parseCurrentBlock();
00159                 }
00160         }
00161         
00167         public function editField()
00168         {
00169                 $_SESSION['il_cdf_select_num_values'] = $_SESSION['il_cdf_select_num_values'] ? $_SESSION['il_cdf_select_num_values'] : 1; 
00170                 
00171                 if(!$_GET['field_id'])
00172                 {
00173                         ilUtil::sendInfo('No field given');
00174                         $this->show();
00175                         return false;
00176                 }
00177                 $cdf = new ilCourseDefinedFieldDefinition($this->obj_id,(int) $_GET['field_id']);
00178                 
00179                 $name = isset($_POST['cmd']) ? ilUtil::prepareFormOutput($_POST['field_name'],true) : ilUtil::prepareFormOutput($cdf->getName());
00180                 $required = isset($_POST['cmd']) ? $_POST['required'] : $cdf->isRequired();             
00181 
00182                 $this->ctrl->setParameter($this,'field_id',(int) $_GET['field_id']);
00183                 $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.user_fields_edit_select_field.html','Modules/Course');
00184                 $this->tpl->setVariable('FORMACTION',$this->ctrl->getFormAction($this));
00185                 
00186                                                 
00187                 $this->tpl->setVariable('TXT_FIELD_NAME',$this->lng->txt('ps_name_field'));
00188                 $this->tpl->setVariable('FIELD_NAME_VALUE',$name);
00189         
00190                 $this->tpl->setVariable('TXT_REQUIRED',$this->lng->txt('required_field'));
00191                 $this->tpl->setVariable('BTN_ADD',$this->lng->txt('save'));
00192                 $this->tpl->setVariable('BTN_PREVIOUS',$this->lng->txt('cancel'));
00193                 
00194                 $this->tpl->setVariable('REQUIRED',ilUtil::formCheckbox($required,'required',1));
00195                 
00196                 // Old values
00197                 $i = 1;
00198                 foreach($cdf->getValues() as $key => $value)
00199                 {
00200                         $this->ctrl->setParameter($this,'del_field',$i - 1);
00201                         
00202                         $this->tpl->setCurrentBlock('values');
00203                         
00204                         $this->ctrl->setParameter($this,'del_field',$i - 1);
00205                         $this->tpl->setVariable('DELETE',$this->lng->txt('delete'));
00206                         $this->tpl->setVariable('LINK_DELETE',$this->ctrl->getLinkTarget($this,'deleteField'));
00207                         $this->tpl->setVariable('FIELD_NAME',ilUtil::prepareFormOutput($value));
00208                         $this->tpl->setVariable("TXT_VALUES",$this->lng->txt('ps_cdf_value').' '.($i++));
00209                         $this->tpl->parseCurrentBlock();
00210                 }
00211                 switch($cdf->getType())
00212                 {
00213                         case IL_CDF_TYPE_SELECT:
00214                                 $this->tpl->setVariable('TXT_SELECT_TYPE',$this->lng->txt('ps_edit_select_field'));
00215                                 $this->tpl->setVariable('BTN_NEW_VALUE',$this->lng->txt('ps_btn_add_value'));
00216                                 // New values
00217                                 for($j = 0; $j < $_SESSION['il_cdf_select_num_values'];$j++)
00218                                 {
00219                                         $this->tpl->setCurrentBlock('new_values');
00220                                         $this->tpl->setVariable('COUNTER',$j);
00221                                         $this->tpl->setVariable("TXT_NEW_VALUES",$this->lng->txt('ps_cdf_value').' '.($i + $j));
00222                                         $this->tpl->setVariable("NEW_FIELD_NAME",$_POST['new_field_values'][$j]);
00223                                         $this->tpl->parseCurrentBlock();
00224                                 }
00225                                 break;
00226                         
00227                         case IL_CDF_TYPE_TEXT:
00228                                 $this->tpl->setVariable('TXT_SELECT_TYPE',$this->lng->txt('ps_edit_text_field'));
00229                                 break;
00230                 }               
00231         }
00232         
00238         public function deleteField()
00239         {
00240                 if(!$_GET['field_id'])
00241                 {
00242                         ilUtil::sendInfo('No field given');
00243                         $this->show();
00244                         return false;
00245                 }
00246                 $cdf = new ilCourseDefinedFieldDefinition($this->obj_id,(int) $_GET['field_id']);
00247                 $cdf->deleteValue((int) $_GET['del_field']);
00248                 
00249                 ilUtil::sendInfo($this->lng->txt('ps_cdf_deleted_field'));
00250                 $this->editField();
00251         }
00252         
00253 
00259         public function addNewValue()
00260         {
00261                 $_SESSION['il_cdf_select_num_values'] += 1;
00262                 $this->editField();
00263                 return true;
00264         }
00265         
00271         public function updateField()
00272         {
00273                 if(!$_GET['field_id'])
00274                 {
00275                         ilUtil::sendInfo('No field given');
00276                         $this->show();
00277                         return false;
00278                 }
00279                 
00280                 $cdf = new ilCourseDefinedFieldDefinition($this->obj_id,$_GET['field_id']);
00281         
00282                 if(!strlen($_POST['field_name']))
00283                 {
00284                         ilUtil::sendInfo($this->lng->txt('ps_cdf_no_name_given'));
00285                         $this->editField();
00286                         return false;
00287                 }
00288 
00289                 switch($cdf->getType())
00290                 {
00291                         case IL_CDF_TYPE_SELECT:
00292                                 $values = $cdf->prepareValues($_POST['new_field_values']);
00293                                 $cdf->appendValues($values);
00294                                 break;
00295                         default:
00296                                 break;
00297                         
00298                 }
00299                 
00300                 $cdf->setName(ilUtil::stripSlashes($_POST['field_name']));
00301                 $cdf->enableRequired((int) $_POST['required']);
00302                 $cdf->update();
00303                 
00304                 // Finally reset member agreements
00305                 ilCourseAgreement::_deleteByObjId($this->obj_id);
00306                 
00307                 ilUtil::sendInfo($this->lng->txt('settings_saved'));
00308                 $this->show();
00309                 return true;
00310         }
00311         
00312         
00313         
00314         
00320         public function confirmDelete()
00321         {
00322                 if(!count($_POST['field_id']))
00323                 {
00324                         ilUtil::sendInfo($this->lng->txt('ps_cdf_select_one'));
00325                         $this->show();
00326                         return false;
00327                 }
00328                 
00329                 ilUtil::sendInfo($this->lng->txt('ps_cdf_delete_sure'));
00330                 $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.user_fields_confirm_delete.html','Modules/Course');
00331                 $this->tpl->setVariable('FORMACTION',$this->ctrl->getFormAction($this));
00332                 $this->tpl->setVariable('TXT_NAME',$this->lng->txt('ps_cdf_name'));
00333                 $this->tpl->setVariable('TXT_TYPE',$this->lng->txt('ps_cdf_type'));
00334                 $this->tpl->setVariable('DELETE',$this->lng->txt('delete'));
00335                 $this->tpl->setVariable('CANCEL',$this->lng->txt('cancel'));
00336                 
00337                 $counter = 0;
00338                 foreach($_POST['field_id'] as $field_id)
00339                 {
00340                         $tmp_field = new ilCourseDefinedFieldDefinition($this->obj_id,$field_id);
00341                         
00342                         $this->tpl->setCurrentBlock('del_row');
00343                         $this->tpl->setVariable('CSS_ROW',ilUtil::switchColor(++$counter,'tblrow1','tblrow2'));
00344                         $this->tpl->setVariable('DEL_NAME',$tmp_field->getName());
00345                         $this->tpl->setVariable('DEL_TYPE',$tmp_field->getType() == IL_CDF_TYPE_SELECT ?
00346                                                                                         $this->lng->txt('ps_type_select') :
00347                                                                                         $this->lng->txt('ps_type_text'));
00348                         $this->tpl->parseCurrentBlock();
00349                 }
00350                 
00351                 $_SESSION['il_cdf_delete'] = $_POST['field_id'];
00352         }
00353         
00359         public function delete()
00360         {
00361                 if(!count($_SESSION['il_cdf_delete']))
00362                 {
00363                         ilUtil::sendInfo($this->lng->txt('ps_cdf_select_one'));
00364                         $this->show();
00365                         return false;
00366                 }
00367                 foreach($_SESSION['il_cdf_delete'] as $field_id)
00368                 {
00369                         $tmp_field = new ilCourseDefinedFieldDefinition($this->obj_id,$field_id);
00370                         $tmp_field->delete();
00371                 }
00372                 
00373                 ilCourseAgreement::_deleteByObjId($this->obj_id);
00374                 
00375                 ilUtil::sendInfo($this->lng->txt('ps_cdf_deleted'));
00376                 unset($_SESSION['il_cdf_delete']);
00377                 
00378                 $this->show();
00379                 return true;
00380         }
00381         
00382         
00383         
00391         public function save()
00392         {
00393                 $fields = ilCourseDefinedFieldDefinition::_getFields($this->obj_id);
00394                 foreach($fields as $field_obj)
00395                 {
00396                         $field_obj->enableRequired((bool) isset($_POST['required'][$field_obj->getId()]));
00397                         $field_obj->update();
00398                 }
00399                 
00400                 ilCourseAgreement::_deleteByObjId($this->obj_id);
00401                 ilUtil::sendInfo($this->lng->txt('settings_saved'));
00402                 $this->show();
00403                 return true;
00404         }
00405         
00412         public function fieldSelection()
00413         {
00414                 // number of values defaults to 3
00415                 $_SESSION['il_cdf_select_num_values'] = 3;
00416                 
00417                 
00418                 $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.user_fields_selection.html','Modules/Course');
00419                 $this->tpl->setVariable('FORMACTION',$this->ctrl->getFormAction($this));
00420                 $this->tpl->setVariable('TXT_SELECT_TYPE',$this->lng->txt('ps_cdf_add_field'));
00421                 $this->tpl->setVariable('FIELD_TYPE',$this->lng->txt('ps_field_type'));
00422                 $this->tpl->setVariable('TXT_TEXT',$this->lng->txt('ps_type_txt_long'));
00423                 $this->tpl->setVariable('TXT_SELECT',$this->lng->txt('ps_type_select_long'));
00424                 $this->tpl->setVariable('BTN_MORE',$this->lng->txt('btn_next'));
00425                 $this->tpl->setVariable('BTN_CANCEL',$this->lng->txt('cancel'));
00426                 
00427                 $this->tpl->setVariable("TYPE_TEXT",ilUtil::formRadioButton(1,'field_type',IL_CDF_TYPE_TEXT));
00428                 $this->tpl->setVariable("TYPE_SELECT",ilUtil::formRadioButton(0,'field_type',IL_CDF_TYPE_SELECT));
00429                         
00430         }
00431         
00438         public function chooseDefinitions()
00439         {
00440                 switch($field_type = (int) $_REQUEST['field_type'])
00441                 {
00442                         case IL_CDF_TYPE_TEXT:
00443                                 $this->addTextField();
00444                                 break;
00445 
00446                         case IL_CDF_TYPE_SELECT:
00447                                 $this->addSelectField();
00448                                 break;
00449                 }
00450         }
00451         
00452         /*
00453          * @access public
00454          */
00455         public function addSelectField()
00456         {
00457                 $_SESSION['il_cdf_select_num_values'] = $_SESSION['il_cdf_select_num_values'] ? $_SESSION['il_cdf_select_num_values'] : 3; 
00458                 
00459                 $this->ctrl->setParameter($this,'field_type',(int) $_REQUEST['field_type']);
00460 
00461                 $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.user_fields_add_select.html','Modules/Course');
00462                 $this->tpl->setVariable('FORMACTION',$this->ctrl->getFormAction($this));
00463                 $this->tpl->setVariable('TXT_SELECT_TYPE',$this->lng->txt('ps_new_select_field'));
00464                 $this->tpl->setVariable('TXT_FIELD_NAME',$this->lng->txt('ps_name_field'));
00465                 $this->tpl->setVariable('TXT_REQUIRED',$this->lng->txt('required_field'));
00466                 $this->tpl->setVariable('BTN_ADD',$this->lng->txt('save'));
00467                 $this->tpl->setVariable('BTN_PREVIOUS',$this->lng->txt('btn_previous'));
00468                 $this->tpl->setVariable('BTN_NEW_VALUE',$this->lng->txt('ps_btn_add_value'));
00469                 
00470                 $this->tpl->setVariable('REQUIRED',ilUtil::formCheckbox($_POST['required'] ? 1 : 0,'required',1));
00471                 $this->tpl->setVariable('FIELD_NAME_VALUE',$_POST['field_name']);
00472                 
00473                 for($i = 0; $i < $_SESSION['il_cdf_select_num_values'];$i++)
00474                 {
00475                         $this->tpl->setCurrentBlock("values");
00476                         $this->tpl->setVariable('COUNTER',$i);
00477                         $this->tpl->setVariable("TXT_VALUES",$this->lng->txt('ps_cdf_value').' '.($i + 1));
00478                         $this->tpl->setVariable("FIELD_NAME",$_POST['field_values'][$i]);
00479                         $this->tpl->parseCurrentBlock();
00480                 }
00481                 
00482         }
00483         
00489         public function addValue()
00490         {
00491                 $_SESSION['il_cdf_select_num_values'] += 1;
00492                 $this->addSelectField();
00493                 return true;
00494         }
00495         
00496         
00497 
00505         public function addTextField()
00506         {
00507                 $this->ctrl->setParameter($this,'field_type',(int) $_REQUEST['field_type']);
00508                 
00509                 $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.user_fields_add_text.html','Modules/Course');
00510                 $this->tpl->setVariable('FORMACTION',$this->ctrl->getFormAction($this));
00511                 $this->tpl->setVariable('TXT_SELECT_TYPE',$this->lng->txt('ps_new_text_field'));
00512                 $this->tpl->setVariable('TXT_FIELD_NAME',$this->lng->txt('ps_name_field'));
00513                 $this->tpl->setVariable('TXT_REQUIRED',$this->lng->txt('required_field'));
00514                 $this->tpl->setVariable('BTN_ADD',$this->lng->txt('btn_add'));
00515                 $this->tpl->setVariable('BTN_PREVIOUS',$this->lng->txt('btn_previous'));
00516                 
00517                 $this->tpl->setVariable('REQUIRED',ilUtil::formCheckbox(0,'required',1));
00518         }
00519 
00525         public function saveField()
00526         {
00527                 $cdf = new ilCourseDefinedFieldDefinition($this->obj_id);
00528         
00529                 if(!strlen($_POST['field_name']))
00530                 {
00531                         ilUtil::sendInfo($this->lng->txt('ps_cdf_no_name_given'));
00532                         $this->chooseDefinitions();
00533                         return false;
00534                 }
00535                 if($_REQUEST['field_type'] == IL_CDF_TYPE_TEXT)
00536                 {
00537                         $cdf->setType(IL_CDF_TYPE_TEXT);
00538                 }
00539                 else
00540                 {
00541                         $cdf->setType(IL_CDF_TYPE_SELECT);
00542                         $values = $cdf->prepareValues($_POST['field_values']);
00543                         $cdf->setValues($values);
00544                 }
00545                 
00546                 $cdf->setName(ilUtil::stripSlashes($_POST['field_name']));
00547                 $cdf->enableRequired((int) $_POST['required']);
00548                 $cdf->save();
00549                 
00550                 ilUtil::sendInfo($this->lng->txt('ps_cdf_added_field'));
00551                 $this->show();
00552                 return true;
00553         }
00554 }
00555 
00556 
00557 ?>

Generated on Fri Dec 13 2013 17:56:49 for ILIAS Release_3_9_x_branch .rev 46835 by  doxygen 1.7.1