/**
  * init form
  *
  * @access protected
  * @param string mode ('edit' | 'create')
  * @return
  */
 protected function initForm($a_mode, $a_as_milestone = false, $a_edit_single_app = false)
 {
     global $ilUser, $tpl;
     include_once './Services/Form/classes/class.ilPropertyFormGUI.php';
     include_once './Services/Calendar/classes/class.ilCalendarRecurrenceGUI.php';
     include_once './Services/Calendar/classes/class.ilCalendarCategories.php';
     include_once './Services/Calendar/classes/class.ilCalendarCategoryAssignments.php';
     include_once './Services/Calendar/classes/class.ilCalendarCategory.php';
     $this->form = new ilPropertyFormGUI();
     include_once './Services/YUI/classes/class.ilYuiUtil.php';
     ilYuiUtil::initDomEvent();
     $resp_info = false;
     switch ($a_mode) {
         case 'create':
             $this->ctrl->saveParameter($this, array('seed', 'idate'));
             $this->form->setFormAction($this->ctrl->getFormAction($this));
             if ($a_as_milestone) {
                 $this->form->setTitle($this->lng->txt('cal_new_ms'));
                 $this->form->addCommandButton('saveMilestone', $this->lng->txt('cal_add_milestone'));
                 $this->form->addCommandButton('cancel', $this->lng->txt('cancel'));
             } else {
                 $this->form->setTitle($this->lng->txt('cal_new_app'));
                 $this->form->addCommandButton('save', $this->lng->txt('cal_add_appointment'));
                 $this->form->addCommandButton('cancel', $this->lng->txt('cancel'));
             }
             break;
         case 'edit':
             if ($a_as_milestone) {
                 $this->form->setTitle($this->lng->txt('cal_edit_milestone'));
             } else {
                 $this->form->setTitle($this->lng->txt('cal_edit_appointment'));
             }
             $this->ctrl->saveParameter($this, array('seed', 'app_id', 'idate'));
             $this->form->setFormAction($this->ctrl->getFormAction($this));
             $ass = new ilCalendarCategoryAssignments($this->app->getEntryId());
             $cat = $ass->getFirstAssignment();
             include_once './Services/Calendar/classes/class.ilCalendarCategory.php';
             $cat_info = ilCalendarCategories::_getInstance()->getCategoryInfo($cat);
             $type = ilObject::_lookupType($cat_info['obj_id']);
             if ($a_as_milestone && $cat_info['type'] == ilCalendarCategory::TYPE_OBJ && ($type == "grp" || $type == "crs")) {
                 $resp_info = true;
                 $this->form->addCommandButton('editResponsibleUsers', $this->lng->txt('cal_change_responsible_users'));
             }
             $this->form->addCommandButton('update', $this->lng->txt('save'));
             // $this->form->addCommandButton('askDelete',$this->lng->txt('delete'));
             $this->form->addCommandButton('cancel', $this->lng->txt('cancel'));
             break;
     }
     // title
     $title = new ilTextInputGUI($this->lng->txt('title'), 'title');
     $title->setValue($this->app->getTitle());
     $title->setRequired(true);
     $title->setMaxLength(128);
     $title->setSize(32);
     $this->form->addItem($title);
     // calendar selection
     $calendar = new ilSelectInputGUI($this->lng->txt('cal_category_selection'), 'calendar');
     if ($_POST['category']) {
         $calendar->setValue((int) $_POST['calendar']);
         $selected_calendar = (int) $_POST['calendar'];
     } else {
         if ($_GET['category_id']) {
             $calendar->setValue((int) $_GET['category_id']);
             $selected_calendar = (int) $_GET['category_id'];
         } elseif ($a_mode == 'edit') {
             $ass = new ilCalendarCategoryAssignments($this->app->getEntryId());
             $cat = $ass->getFirstAssignment();
             $calendar->setValue($cat);
             $selected_calendar = $cat;
         } elseif (isset($_GET['ref_id'])) {
             include_once './Services/Calendar/classes/class.ilCalendarCategories.php';
             $obj_cal = ilObject::_lookupObjId($_GET['ref_id']);
             $calendar->setValue(ilCalendarCategories::_lookupCategoryIdByObjId($obj_cal));
             $selected_calendar = ilCalendarCategories::_lookupCategoryIdByObjId($obj_cal);
         }
     }
     $calendar->setRequired(true);
     $cats = ilCalendarCategories::_getInstance($ilUser->getId());
     $calendar->setOptions($cats->prepareCategoriesOfUserForSelection());
     include_once './Services/Calendar/classes/class.ilCalendarSettings.php';
     if (ilCalendarSettings::_getInstance()->isNotificationEnabled()) {
         $notification_cals = $cats->getNotificationCalendars();
         $notification_cals = count($notification_cals) ? implode(',', $notification_cals) : '';
         $calendar->addCustomAttribute("onchange=\"ilToggleNotification(new Array(" . $notification_cals . "));\"");
     }
     $this->form->addItem($calendar);
     if (!$a_as_milestone) {
         include_once './Services/Form/classes/class.ilDateDurationInputGUI.php';
         $tpl->addJavaScript('./Services/Form/js/date_duration.js');
         $dur = new ilDateDurationInputGUI($this->lng->txt('cal_fullday'), 'event');
         $dur->setStartText($this->lng->txt('cal_start'));
         $dur->setEndText($this->lng->txt('cal_end'));
         $dur->enableToggleFullTime($this->lng->txt('cal_fullday_title'), $this->app->isFullday() ? true : false);
         $dur->setShowTime(true);
         $dur->setStart($this->app->getStart());
         $dur->setEnd($this->app->getEnd());
         $this->form->addItem($dur);
         // recurrence
         include_once './Services/Calendar/classes/Form/class.ilRecurrenceInputGUI.php';
         $rec = new ilRecurrenceInputGUI($this->lng->txt('cal_recurrences'), 'frequence');
         $rec->setRecurrence($this->rec);
         $this->form->addItem($rec);
         // location
         $where = new ilTextInputGUI($this->lng->txt('cal_where'), 'location');
         $where->setValue($this->app->getLocation());
         $where->setMaxLength(128);
         $where->setSize(32);
         $this->form->addItem($where);
     } else {
         $deadline = new ilDateTimeInputGUI($this->lng->txt('cal_deadline'), 'event[start]');
         $deadline->setDate($this->app->getStart());
         $deadline->setShowTime(false);
         $deadline->setMinuteStepSize(5);
         $this->form->addItem($deadline);
         // completion
         $completion_vals = array();
         for ($i = 0; $i <= 100; $i += 5) {
             $completion_vals[$i] = $i . " %";
         }
         $compl = new ilSelectInputGUI($this->lng->txt('cal_task_completion'), 'completion');
         $compl->setOptions($completion_vals);
         $compl->setValue($this->app->getCompletion());
         $this->form->addItem($compl);
     }
     $desc = new ilTextAreaInputGUI($this->lng->txt('description'), 'description');
     $desc->setValue($this->app->getDescription());
     $desc->setRows(5);
     $this->form->addItem($desc);
     if ($a_as_milestone && $a_mode == "edit" && $resp_info) {
         // users responsible
         $users = $this->app->readResponsibleUsers();
         $resp = new ilNonEditableValueGUI($this->lng->txt('cal_responsible'), $users);
         $delim = "";
         foreach ($users as $r) {
             $value .= $delim . $r["lastname"] . ", " . $r["firstname"] . " [" . $r["login"] . "]";
             $delim = "<br />";
         }
         if (count($users) > 0) {
             $resp->setValue($value);
         } else {
             $resp->setValue("-");
         }
         $this->form->addItem($resp);
     }
     if (ilCalendarSettings::_getInstance()->isUserNotificationEnabled()) {
         $notu = new ilTextWizardInputGUI($this->lng->txt('cal_user_notification'), 'notu');
         $notu->setInfo($this->lng->txt('cal_user_notification_info'));
         $notu->setSize(20);
         $notu->setMaxLength(64);
         $values = array();
         foreach ($this->notification->getRecipients() as $rcp) {
             switch ($rcp['type']) {
                 case ilCalendarUserNotification::TYPE_USER:
                     $values[] = ilObjUser::_lookupLogin($rcp['usr_id']);
                     break;
                 case ilCalendarUserNotification::TYPE_EMAIL:
                     $values[] = $rcp['email'];
                     break;
             }
         }
         if (count($values)) {
             $notu->setValues($values);
         } else {
             $notu->setValues(array(''));
         }
         $this->form->addItem($notu);
     }
     // Notifications
     include_once './Services/Calendar/classes/class.ilCalendarSettings.php';
     if (ilCalendarSettings::_getInstance()->isNotificationEnabled() and count($cats->getNotificationCalendars())) {
         $selected_cal = new ilCalendarCategory($selected_calendar);
         $disabled = true;
         if ($selected_cal->getType() == ilCalendarCategory::TYPE_OBJ) {
             if (ilObject::_lookupType($selected_cal->getObjId()) == 'crs' or ilObject::_lookupType($selected_cal->getObjId()) == 'grp') {
                 $disabled = false;
             }
         }
         $tpl->addJavaScript('./Services/Calendar/js/toggle_notification.js');
         $not = new ilCheckboxInputGUI($this->lng->txt('cal_cg_notification'), 'not');
         $not->setInfo($this->lng->txt('cal_notification_info'));
         $not->setValue(1);
         $not->setChecked($this->app->isNotificationEnabled());
         $not->setDisabled($disabled);
         $this->form->addItem($not);
     }
 }
 /**
  * Init field form
  * 
  * @param string $a_mode 
  * @return ilPropertyFormGUI
  */
 function initForm($a_mode = "create")
 {
     global $ilCtrl, $lng;
     include_once "Services/Membership/classes/class.ilMemberAgreement.php";
     if (ilMemberAgreement::_hasAgreements()) {
         $lng->loadLanguageModule("ps");
         ilUtil::sendInfo($lng->txt("ps_warning_modify"));
     }
     if ($this->field_definition) {
         $perms = $this->permissions->hasPermissions(ilUDFPermissionHelper::CONTEXT_FIELD, $this->field_definition["field_id"], array(array(ilUDFPermissionHelper::ACTION_FIELD_EDIT_PROPERTY, ilUDFPermissionHelper::SUBACTION_FIELD_TITLE), array(ilUDFPermissionHelper::ACTION_FIELD_EDIT_PROPERTY, ilUDFPermissionHelper::SUBACTION_FIELD_PROPERTIES), array(ilUDFPermissionHelper::ACTION_FIELD_EDIT_ACCESS, ilUDFPermissionHelper::SUBACTION_FIELD_ACCESS_VISIBLE_PERSONAL), array(ilUDFPermissionHelper::ACTION_FIELD_EDIT_ACCESS, ilUDFPermissionHelper::SUBACTION_FIELD_ACCESS_VISIBLE_REGISTRATION), array(ilUDFPermissionHelper::ACTION_FIELD_EDIT_ACCESS, ilUDFPermissionHelper::SUBACTION_FIELD_ACCESS_VISIBLE_LOCAL), array(ilUDFPermissionHelper::ACTION_FIELD_EDIT_ACCESS, ilUDFPermissionHelper::SUBACTION_FIELD_ACCESS_VISIBLE_COURSES), array(ilUDFPermissionHelper::ACTION_FIELD_EDIT_ACCESS, ilUDFPermissionHelper::SUBACTION_FIELD_ACCESS_VISIBLE_GROUPS), array(ilUDFPermissionHelper::ACTION_FIELD_EDIT_ACCESS, ilUDFPermissionHelper::SUBACTION_FIELD_ACCESS_CHANGEABLE_PERSONAL), array(ilUDFPermissionHelper::ACTION_FIELD_EDIT_ACCESS, ilUDFPermissionHelper::SUBACTION_FIELD_ACCESS_CHANGEABLE_LOCAL), array(ilUDFPermissionHelper::ACTION_FIELD_EDIT_ACCESS, ilUDFPermissionHelper::SUBACTION_FIELD_ACCESS_REQUIRED), array(ilUDFPermissionHelper::ACTION_FIELD_EDIT_ACCESS, ilUDFPermissionHelper::SUBACTION_FIELD_ACCESS_EXPORT), array(ilUDFPermissionHelper::ACTION_FIELD_EDIT_ACCESS, ilUDFPermissionHelper::SUBACTION_FIELD_ACCESS_SEARCHABLE), array(ilUDFPermissionHelper::ACTION_FIELD_EDIT_ACCESS, ilUDFPermissionHelper::SUBACTION_FIELD_ACCESS_CERTIFICATE)));
         $perm_map = self::getAccessPermissions();
     }
     include_once "./Services/Form/classes/class.ilPropertyFormGUI.php";
     $form = new ilPropertyFormGUI();
     $form->setFormAction($ilCtrl->getFormAction($this));
     $name = new ilTextInputGUI($lng->txt("field_name"), "name");
     $name->setRequired(true);
     $form->addItem($name);
     if ($perms && !$perms[ilUDFPermissionHelper::ACTION_FIELD_EDIT_PROPERTY][ilUDFPermissionHelper::SUBACTION_FIELD_TITLE]) {
         $name->setDisabled(true);
     }
     // type
     $radg = new ilRadioGroupInputGUI($lng->txt("field_type"), "field_type");
     $radg->setRequired(true);
     $op1 = new ilRadioOption($lng->txt("udf_type_text"), UDF_TYPE_TEXT);
     $radg->addOption($op1);
     $op2 = new ilRadioOption($lng->txt("udf_type_select"), UDF_TYPE_SELECT);
     $radg->addOption($op2);
     $op3 = new ilRadioOption($lng->txt("udf_type_wysiwyg"), UDF_TYPE_WYSIWYG);
     $radg->addOption($op3);
     $form->addItem($radg);
     // select values
     $se_mu = new ilTextWizardInputGUI($lng->txt("value"), "selvalue");
     $se_mu->setRequired(true);
     $se_mu->setSize(32);
     $se_mu->setMaxLength(128);
     $se_mu->setValues(array(''));
     $op2->addSubItem($se_mu);
     if ($perms && !$perms[ilUDFPermissionHelper::ACTION_FIELD_EDIT_PROPERTY][ilUDFPermissionHelper::SUBACTION_FIELD_PROPERTIES]) {
         $se_mu->setDisabled(true);
         $se_mu->setRequired(false);
     }
     // access
     $acc = new ilCheckboxGroupInputGUI($lng->txt("access"), "access");
     $acc_values = array();
     foreach ($this->getAccessOptions() as $id => $caption) {
         $opt = new ilCheckboxOption($caption, $id);
         $acc->addOption($opt);
         if ($this->field_definition && $this->field_definition[$id]) {
             $acc_values[] = $id;
         }
         if ($perms && !$perms[ilUDFPermissionHelper::ACTION_FIELD_EDIT_ACCESS][$perm_map[$id]]) {
             $opt->setDisabled(true);
         }
     }
     $form->addItem($acc);
     if ($a_mode == "create") {
         $radg->setValue(UDF_TYPE_TEXT);
         $form->setTitle($lng->txt('add_new_user_defined_field'));
         $form->addCommandButton("create", $lng->txt("save"));
         $form->addCommandButton("listUserDefinedFields", $lng->txt("cancel"));
     } else {
         $name->setValue($this->field_definition["field_name"]);
         $radg->setValue($this->field_definition["field_type"]);
         $radg->setDisabled(true);
         $acc->setValue($acc_values);
         switch ($this->field_definition["field_type"]) {
             case UDF_TYPE_SELECT:
                 $se_mu->setValue($this->field_definition["field_values"]);
                 $form->setTitle($lng->txt("udf_update_select_field"));
                 break;
             case UDF_TYPE_TEXT:
                 $form->setTitle($lng->txt("udf_update_text_field"));
                 break;
             case UDF_TYPE_WYSIWYG:
                 $form->setTitle($lng->txt("udf_update_wysiwyg_field"));
                 break;
         }
         $form->addCommandButton("update", $lng->txt("save"));
         $form->addCommandButton("listUserDefinedFields", $lng->txt("cancel"));
     }
     return $form;
 }
 /**
  * Init field form
  * 
  * @param string $a_mode 
  * @return ilPropertyFormGUI
  */
 function initForm($a_mode = "create")
 {
     global $ilCtrl, $lng;
     include_once "Services/Membership/classes/class.ilMemberAgreement.php";
     if (ilMemberAgreement::_hasAgreements()) {
         $lng->loadLanguageModule("ps");
         ilUtil::sendInfo($lng->txt("ps_warning_modify"));
     }
     include_once "./Services/Form/classes/class.ilPropertyFormGUI.php";
     $form = new ilPropertyFormGUI();
     $form->setFormAction($ilCtrl->getFormAction($this));
     $name = new ilTextInputGUI($lng->txt("field_name"), "name");
     $name->setRequired(true);
     $form->addItem($name);
     // type
     $radg = new ilRadioGroupInputGUI($lng->txt("field_type"), "field_type");
     $radg->setRequired(true);
     $op1 = new ilRadioOption($lng->txt("udf_type_text"), UDF_TYPE_TEXT);
     $radg->addOption($op1);
     $op2 = new ilRadioOption($lng->txt("udf_type_select"), UDF_TYPE_SELECT);
     $radg->addOption($op2);
     $op3 = new ilRadioOption($lng->txt("udf_type_wysiwyg"), UDF_TYPE_WYSIWYG);
     $radg->addOption($op3);
     $form->addItem($radg);
     // select values
     $se_mu = new ilTextWizardInputGUI($lng->txt("value"), "selvalue");
     $se_mu->setRequired(true);
     $se_mu->setSize(32);
     $se_mu->setMaxLength(128);
     $se_mu->setValues(array(''));
     $op2->addSubItem($se_mu);
     // access
     $acc = new ilCheckboxGroupInputGUI($lng->txt("access"), "access");
     $acc_values = array();
     foreach ($this->getAccessOptions() as $id => $caption) {
         $opt = new ilCheckboxOption($caption, $id);
         $acc->addOption($opt);
         if ($this->field_definition && $this->field_definition[$id]) {
             $acc_values[] = $id;
         }
     }
     $form->addItem($acc);
     if ($a_mode == "create") {
         $radg->setValue(UDF_TYPE_TEXT);
         $form->setTitle($lng->txt('add_new_user_defined_field'));
         $form->addCommandButton("create", $lng->txt("save"));
         $form->addCommandButton("listUserDefinedFields", $lng->txt("cancel"));
     } else {
         $name->setValue($this->field_definition["field_name"]);
         $radg->setValue($this->field_definition["field_type"]);
         $radg->setDisabled(true);
         $acc->setValue($acc_values);
         switch ($this->field_definition["field_type"]) {
             case UDF_TYPE_SELECT:
                 $se_mu->setValue($this->field_definition["field_values"]);
                 $form->setTitle($lng->txt("udf_update_select_field"));
                 break;
             case UDF_TYPE_TEXT:
                 $form->setTitle($lng->txt("udf_update_text_field"));
                 break;
             case UDF_TYPE_WYSIWYG:
                 $form->setTitle($lng->txt("udf_update_wysiwyg_field"));
                 break;
         }
         $form->addCommandButton("update", $lng->txt("save"));
         $form->addCommandButton("listUserDefinedFields", $lng->txt("cancel"));
     }
     return $form;
 }
 /**
  * Init/create property form for fields
  * @return 
  */
 protected function initFieldForm($a_mode)
 {
     if ($this->form instanceof ilPropertyFormGUI) {
         return true;
     }
     include_once './Services/Form/classes/class.ilPropertyFormGUI.php';
     $this->form = new ilPropertyFormGUI();
     switch ($a_mode) {
         case self::MODE_CREATE:
             $this->form->setFormAction($this->ctrl->getFormAction($this));
             $this->form->setTitle($this->lng->txt('ps_cdf_add_field'));
             $this->form->addCommandButton('saveField', $this->lng->txt('save'));
             $this->form->addCommandButton('listFields', $this->lng->txt('cancel'));
             break;
         case self::MODE_UPDATE:
             $this->ctrl->setParameter($this, 'field_id', (int) $_REQUEST['field_id']);
             $this->form->setFormAction($this->ctrl->getFormAction($this));
             $this->form->setTitle($this->lng->txt('ps_cdf_edit_field'));
             $this->form->addCommandButton('updateField', $this->lng->txt('save'));
             $this->form->addCommandButton('listFields', $this->lng->txt('cancel'));
             break;
     }
     // Name
     $na = new ilTextInputGUI($this->lng->txt('ps_cdf_name'), 'na');
     $na->setSize(32);
     $na->setMaxLength(255);
     $na->setRequired(true);
     $this->form->addItem($na);
     // Type
     $ty = new ilRadioGroupInputGUI($this->lng->txt('ps_field_type'), 'ty');
     $ty->setRequired(true);
     $this->form->addItem($ty);
     //		Text type
     $ty_te = new ilRadioOption($this->lng->txt('ps_type_txt_long'), IL_CDF_TYPE_TEXT);
     $ty->addOption($ty_te);
     //		Select Type
     $ty_se = new ilRadioOption($this->lng->txt('ps_type_select_long'), IL_CDF_TYPE_SELECT);
     $ty->addOption($ty_se);
     //			Select Type Values
     $ty_se_mu = new ilTextWizardInputGUI($this->lng->txt('ps_cdf_value'), 'va');
     $ty_se_mu->setRequired(true);
     $ty_se_mu->setSize(32);
     $ty_se_mu->setMaxLength(128);
     $ty_se->addSubItem($ty_se_mu);
     // Required
     $re = new ilCheckboxInputGUI($this->lng->txt('ps_cdf_required'), 're');
     $re->setValue(1);
     $this->form->addItem($re);
 }