/**
  * Save config
  */
 public function save()
 {
     $form = new ilCertificateConfigFormGUI($this);
     if ($form->saveObject()) {
         ilUtil::sendSuccess($this->pl->txt('msg_save_config'), true);
         $this->ctrl->redirect($this, 'configure');
     } else {
         $form->setValuesByPost();
         $this->tpl->setContent($form->getHTML());
     }
 }
 /**
  * Get dropdown for choosing the certificate type
  *
  * @return ilSelectInputGUI
  */
 protected function getTypeInput()
 {
     $types = srcertificateType::get();
     $options = array();
     $object_type = $this->pl->isCourseTemplate((int) $_GET['ref_id']) ? 'crs-tpl' : ilObject::_lookupType((int) $_GET['ref_id'], true);
     /** @var $type srCertificateType */
     $invalid = array();
     foreach ($types as $type) {
         if (!srCertificateType::isSelectable($type, (int) $_GET['ref_id'])) {
             continue;
         }
         // Skip the type if it contains no valid template file!
         if (!is_file($type->getCertificateTemplatesPath(true))) {
             $invalid[] = $type->getTitle();
             continue;
         }
         $options[$type->getId()] = $type->getTitle();
     }
     if (count($invalid) && $this->isNew) {
         ilUtil::sendInfo(sprintf($this->pl->txt('msg_info_invalid_cert_types'), implode(', ', $invalid)));
     }
     $item = new ilSelectInputGUI($this->pl->txt('setting_id_type'), 'type_id');
     asort($options);
     $item->setOptions($options);
     $info = $this->isNew ? $this->pl->txt('setting_id_type_info_new') : $this->pl->txt('setting_id_type_info_change');
     $item->setInfo($info);
     $item->setValue($this->definition->getTypeId());
     $item->setRequired(true);
     return $item;
 }
 /**
  * Get settings
  */
 protected function buildData()
 {
     $data = array();
     /** @var $setting srCertificateTypeSetting */
     foreach ($this->type->getSettings() as $setting) {
         $row = array();
         $row['identifier'] = $setting->getIdentifier();
         $row['setting'] = $this->pl->txt("setting_id_" . $setting->getIdentifier());
         $row['editable_in'] = implode(',', $setting->getEditableIn());
         $default_value = $setting->getValue();
         switch ($setting->getIdentifier()) {
             case srCertificateTypeSetting::IDENTIFIER_VALIDITY_TYPE:
                 $default_value = $this->pl->txt("setting_validity_{$default_value}");
                 break;
             case srCertificateTypeSetting::IDENTIFIER_VALIDITY:
                 $validity_type = $this->type->getSettingByIdentifier(srCertificateTypeSetting::IDENTIFIER_VALIDITY_TYPE)->getValue();
                 if ($default_value && $validity_type == srCertificateTypeSetting::VALIDITY_TYPE_DATE_RANGE) {
                     $date_data = json_decode($default_value);
                     $default_value = sprintf($this->pl->txt('validity_date_range'), $date_data->m, $date_data->d);
                 }
                 break;
         }
         $row['default_value'] = $default_value;
         $data[] = $row;
     }
     $this->setData($data);
 }
 protected function initForm()
 {
     $this->setFormAction($this->ctrl->getFormAction($this->parent_gui));
     $this->setTitle($this->pl->txt('certificate_placeholders'));
     // Each placeholder can define values for each language defined in the type
     $languages = $this->definition->getType()->getLanguages();
     $label_lang = in_array($this->user->getLanguage(), $languages) ? $this->user->getLanguage() : $this->definition->getDefaultLanguage();
     /** @var $placeholder_value srCertificatePlaceholderValue */
     foreach ($this->definition->getPlaceholderValues() as $placeholder_value) {
         $section = new ilFormSectionHeaderGUI();
         $section->setTitle($placeholder_value->getPlaceholder()->getLabel($label_lang));
         $this->addItem($section);
         foreach ($languages as $lang) {
             $this->addItem($this->getInputField($placeholder_value, $lang));
         }
     }
     if ($signatures = $this->definition->getType()->getSignatures()) {
         $section = new ilFormSectionHeaderGUI();
         $section->setTitle($this->pl->txt('signature'));
         $this->addItem($section);
         $select_input = new ilSelectInputGUI($this->pl->txt('signature'), 'signature');
         $options = array(0 => '');
         foreach ($signatures as $signature) {
             $options[$signature->getId()] = $signature->getFirstName() . ' ' . $signature->getLastName();
         }
         $select_input->setOptions($options);
         $select_input->setValue($this->definition->getSignatureId());
         $this->addItem($select_input);
     }
     $this->addCommandButton('updatePlaceholders', $this->pl->txt('save'));
     return;
 }
 /**
  * Add columns
  */
 protected function initColumns()
 {
     foreach ($this->columns as $column) {
         $this->addColumn($this->pl->txt($column), $column);
     }
     $this->addColumn($this->pl->txt('actions'));
 }
 /**
  * @return array
  */
 public function getSelectableColumns()
 {
     $columns = array();
     foreach ($this->columns as $column) {
         $columns[$column] = array('txt' => $this->pl->txt($column), 'default' => true);
     }
     return $columns;
 }
 protected function addLabelInput($lang_code)
 {
     $section = new ilFormSectionHeaderGUI();
     $section->setTitle($this->lng->txt("meta_l_{$lang_code}"));
     $this->addItem($section);
     $item = new ilTextInputGUI($this->pl->txt('label'), "label_{$lang_code}");
     $item->setValue($this->setting->getLabel($lang_code));
     $item->setRequired(true);
     $this->addItem($item);
 }
 /**
  * Add columns
  */
 protected function initColumns()
 {
     foreach ($this->columns as $column) {
         $this->addColumn($this->pl->txt($column), $column);
     }
     foreach ($this->type->getLanguages() as $lang_code) {
         $this->addColumn(sprintf($this->pl->txt('default_value_lang'), $lang_code), "default_value_{$lang_code}");
         $this->addColumn(sprintf($this->pl->txt('label_lang'), $lang_code), "label_{$lang_code}");
     }
 }
 /**
  * Set Course title and icon in header
  *
  */
 protected function initHeader()
 {
     $lgui = ilObjectListGUIFactory::_getListGUIByType($this->crs->getType());
     $this->tpl->setTitle($this->crs->getTitle());
     $this->tpl->setDescription($this->crs->getDescription());
     if ($this->crs->getOfflineStatus()) {
         $this->tpl->setAlertProperties($lgui->getAlertProperties());
     }
     $this->tpl->setTitleIcon(ilUtil::getTypeIconPath('crs', $this->crs->getId(), 'big'));
     $this->ctrl->setParameterByClass('ilrepositorygui', 'ref_id', $this->ref_id);
     $this->tabs->setBackTarget($this->pl->txt('back_to_course'), $this->ctrl->getLinkTargetByClass('ilrepositorygui'));
 }
 /**
  * Create or update a type
  */
 public function saveType()
 {
     $type = $this->type === NULL ? new srCertificateType() : $this->type;
     $form = new srCertificateTypeFormGUI($this, $type);
     if ($form->saveObject()) {
         ilUtil::sendSuccess($this->pl->txt('msg_type_saved'), true);
         $this->ctrl->setParameter($this, 'type_id', $type->getId());
         $this->ctrl->redirect($this, 'editType');
     } else {
         $this->tpl->setContent($form->getHTML());
     }
 }
 /**
  * Init form
  */
 protected function initForm()
 {
     $this->setFormAction($this->ctrl->getFormAction($this->parent_gui));
     $title = $this->isNew ? $this->pl->txt('add_new_type') : $this->pl->txt('edit_type');
     $this->setTitle($title);
     $item = new ilTextInputGUI($this->lng->txt('title'), 'title');
     $item->setRequired(true);
     $item->setValue($this->type->getTitle());
     $this->addItem($item);
     $item = new ilTextAreaInputGUI($this->lng->txt('description'), 'description');
     $item->setValue($this->type->getDescription());
     $this->addItem($item);
     $item = new ilMultiSelectInputGUI($this->lng->txt('languages'), 'languages');
     $item->setWidth(self::WIDTH_MULTISELECT_INPUT);
     $langs = $this->lng->getInstalledLanguages();
     $options = array();
     foreach ($langs as $lang_code) {
         $options[$lang_code] = $this->lng->txt("meta_l_{$lang_code}");
     }
     $item->setOptions($options);
     $item->setValue($this->type->getLanguages());
     $item->setRequired(true);
     $this->addItem($item);
     $item = new ilMultiSelectInputGUI($this->lng->txt('roles'), 'roles');
     $item->setWidth(self::WIDTH_MULTISELECT_INPUT);
     $roles = $this->rbac->getRolesByFilter(ilRbacReview::FILTER_ALL, 0, '');
     $options = array();
     $hide_roles = array(14, 5);
     foreach ($roles as $role) {
         if (strpos($role['title'], 'il_') === 0 || in_array($role['obj_id'], $hide_roles)) {
             // Don't show auto-generated roles. If this takes to much performance, write query...
             continue;
         }
         $options[$role['obj_id']] = $role['title'];
     }
     $item->setOptions($options);
     $item->setValue($this->type->getRoles());
     $item->setInfo($this->pl->txt('roles_info'));
     $this->addItem($item);
     $item = new ilMultiSelectInputGUI($this->pl->txt('available_objects'), 'available_objects');
     $item->setWidth(self::WIDTH_MULTISELECT_INPUT);
     $options = array();
     foreach (srCertificateType::getAllAvailableObjectTypes() as $type) {
         $options[$type] = $type;
     }
     $item->setOptions($options);
     $item->setValue($this->type->getAvailableObjects());
     $item->setRequired(true);
     $item->setInfo($this->pl->txt('available_objects_info'));
     $this->addItem($item);
     $this->addCommandButton('saveType', $this->lng->txt('save'));
 }
 /**
  * Parse general placeholders, mostly certificate data
  *
  * @param ilObjCourse $course
  * @return array
  */
 protected function parseGeneralPlaceholders(ilObjCourse $course)
 {
     $utc = ilCertificateConfig::get('time_format_utc');
     $cert_valid_from = strtotime($this->certificate->getValidFrom());
     $cert_valid_to = strtotime($this->certificate->getValidTo());
     if ($utc) {
         // fix for timezone issue: when converting a mysql date into a timestamp and then into another timezone, its possible the date changes (because the start date is the first second of the day).
         // We now add 12*60*60 seconds to be in the middle of the day
         $cert_valid_to += srCertificate::TIME_ZONE_CORRECTION;
         $cert_valid_from += srCertificate::TIME_ZONE_CORRECTION;
     }
     $placeholder = array('DATE' => $this->formatDate('DATE'), 'DATETIME' => $this->formatDateTime('DATETIME'), 'TIMESTAMP' => $utc ? strtotime(gmdate('Y-m-d H:i:s')) : time(), 'CERT_FILE_NAME' => $this->certificate->getFilename(), 'CERT_FILE_VERSION' => $this->certificate->getFileVersion(), 'CERT_VALID_FROM' => $this->certificate->getValidFrom() == '' ? $this->pl->txt('unlimited') : $this->formatDate('CERT_VALID_FROM', $cert_valid_from), 'CERT_VALID_TO' => $this->certificate->getValidTo() == '' ? $this->pl->txt('unlimited') : $this->formatDate('CERT_VALID_TO', $cert_valid_to), 'CERT_ID' => $this->certificate->getId(), 'CERT_TEMPLATE_PATH' => $this->certificate->getDefinition()->getType()->getCertificateTemplatesPath(), 'CERT_TYPE_TITLE' => $this->certificate->getDefinition()->getType()->getTitle(), 'CERT_TYPE_DESCRIPTION' => $this->certificate->getDefinition()->getType()->getDescription(), 'COURSE_TITLE' => $course->getTitle());
     return $placeholder;
 }
 /**
  * Init form
  */
 protected function initForm()
 {
     $this->setFormAction($this->ctrl->getFormAction($this->parent_gui));
     $this->setTitle($this->pl->txt('edit_type_template'));
     $types_available = array();
     $types = array(srCertificateTemplateTypeFactory::getById(srCertificateTemplateType::TEMPLATE_TYPE_HTML), srCertificateTemplateTypeFactory::getById(srCertificateTemplateType::TEMPLATE_TYPE_JASPER));
     /** @var $type srCertificateTemplateType */
     foreach ($types as $type) {
         if ($type->isAvailable()) {
             $types_available[$type->getId()] = $type->getTitle();
         }
     }
     if (!count($types_available)) {
         ilUtil::sendInfo($this->pl->txt('msg_no_template_types'));
     }
     $item = new ilSelectInputGUI($this->pl->txt('template_type_id'), 'template_type_id');
     $item->setOptions($types_available);
     $item->setRequired(true);
     $item->setValue($this->type->getTemplateTypeId());
     $this->addItem($item);
     $item = new ilFileInputGUI($this->pl->txt('template_file'), 'template_file');
     $template_file = $this->type->getCertificateTemplatesPath(true);
     if (is_file($template_file)) {
         $item->setValue($template_file);
     }
     $item->setFilename($template_file);
     $item->setInfo($this->pl->txt('template_file_info'));
     $item->setRequired(!is_file($template_file));
     $this->addItem($item);
     $assets = $this->type->getAssets();
     if (count($assets)) {
         $item = new ilMultiSelectInputGUI($this->pl->txt('assets'), 'remove_assets');
         $options = array();
         foreach ($assets as $asset) {
             $options[$asset] = $asset;
         }
         $item->setOptions($options);
         $item->setInfo($this->pl->txt('assets_info'));
         $this->addItem($item);
     }
     $item = new ilFileWizardInputGUI($this->pl->txt('add_assets'), 'add_assets');
     $item->setFilenames(array(0 => ''));
     $this->addItem($item);
     $this->addCommandButton('downloadDefaultTemplate', $this->pl->txt('download_default_template'));
     if (is_file($this->type->getCertificateTemplatesPath(true))) {
         $this->addCommandButton('downloadTemplate', $this->pl->txt('download_template'));
     }
     $this->addCommandButton('updateTemplate', $this->lng->txt('save'));
 }
 /**
  * Download a certificate
  *
  */
 public function downloadCertificate()
 {
     if ($cert_id = (int) $_GET['cert_id']) {
         /** @var srCertificate $cert */
         $cert = srCertificate::find($cert_id);
         if ($cert->getStatus() == srCertificate::STATUS_CALLED_BACK) {
             ilUtil::sendFailure($this->pl->txt('msg_called_back'));
         } elseif ($cert->getStatus() != srCertificate::STATUS_PROCESSED) {
             ilUtil::sendFailure($this->pl->txt('msg_not_created_yet'));
         } else {
             $cert->download();
         }
     }
     $this->index();
 }
 /**
  * Get settings
  */
 protected function buildData()
 {
     $data = array();
     /** @var $setting srCertificateCustomTypeSetting */
     foreach ($this->type->getCustomSettings() as $setting) {
         $row = array();
         $row['id'] = $setting->getId();
         $row['identifier'] = $setting->getIdentifier();
         $row['editable_in'] = implode(',', $setting->getEditableIn());
         $row['setting_type'] = $this->pl->txt('custom_setting_type_' . $setting->getSettingTypeId());
         $row['default_value'] = $setting->getValue();
         $data[] = $row;
     }
     $this->setData($data);
 }
 /**
  * Init form
  */
 protected function initForm()
 {
     $title = $this->signature->getId() ? $this->pl->txt('edit_signature') : $this->pl->txt('add_new_signature');
     $this->setTitle($title);
     $this->setFormAction($this->ctrl->getFormAction($this->parent_gui));
     $item = new ilTextInputGUI($this->pl->txt('first_name'), 'first_name');
     $item->setValue($this->signature->getFirstName());
     $item->setRequired(true);
     $this->addItem($item);
     $item = new ilTextInputGUI($this->pl->txt('last_name'), 'last_name');
     $item->setValue($this->signature->getLastName());
     $item->setRequired(true);
     $this->addItem($item);
     // If the signature is a rasterized image, we display it base64 encoded
     $is_vector = in_array(strtolower($this->signature->getSuffix()), array('svg'));
     if ($is_vector) {
         $item = new ilFileInputGUI($this->pl->txt('signature_file'), 'signature_file');
     } else {
         $item = new ilImageFileInputGUI($this->pl->txt('signature_file'), 'signature_file');
     }
     $item->setSuffixes(array('jpeg', 'jpg', 'gif', 'bmp', 'png', 'svg'));
     $signature_file = $this->signature->getFilePath(true);
     if (is_file($signature_file) && !$is_vector) {
         $item->setValue($signature_file);
         $base64 = base64_encode(file_get_contents($signature_file));
         $suffix = $this->signature->getSuffix();
         $item->setImage("data:image/{$suffix};base64,{$base64}");
     }
     $item->setFilename($signature_file);
     $item->setInfo($this->pl->txt('signature_file_info'));
     $item->setRequired(!is_file($signature_file));
     $item->setValue($this->signature->getFilePath(true));
     $this->addItem($item);
     $command = $this->signature->getId() ? 'updateSignature' : 'createSignature';
     $this->addCommandButton($command, $this->lng->txt('save'));
 }
 /**
  * @param $field
  *
  * @return string
  */
 public function txt($field)
 {
     return $this->pl->txt('admin_form_' . $field);
 }
 /**
  * @param string $identifier
  * @throws srCertificateException
  */
 public function setIdentifier($identifier)
 {
     if (!preg_match(self::REGEX_VALID_IDENTIFIER, $identifier)) {
         throw new srCertificateException(sprintf($this->pl->txt('msg_identifier_not_valid'), $identifier));
     }
     if (srCertificateStandardPlaceholders::isReservedIdentifier($identifier)) {
         throw new srCertificateException(sprintf($this->pl->txt('msg_reserved_identifier'), $identifier));
     }
     $this->identifier = $identifier;
 }
 /**
  * Get input GUI depending on identifier
  *
  * @return ilFormPropertyGUI|null
  */
 protected function getInputByIdentifier()
 {
     $name = 'default_value';
     $title = $this->pl->txt('default_value');
     switch ($this->identifier) {
         case srCertificateTypeSetting::IDENTIFIER_DEFAULT_LANG:
             $input = new ilSelectInputGUI($title, $name);
             $options = array();
             foreach ($this->type->getLanguages() as $lang) {
                 $options[$lang] = $this->lng->txt("meta_l_{$lang}");
             }
             $input->setOptions($options);
             $input->setValue($this->setting->getValue());
             break;
         case srCertificateTypeSetting::IDENTIFIER_GENERATION:
             $input = new ilRadioGroupInputGUI($title, $name);
             $option = new ilRadioOption($this->pl->txt('setting_generation_auto'), srCertificateTypeSetting::GENERATION_AUTO);
             $input->addOption($option);
             $option = new ilRadioOption($this->pl->txt('setting_generation_manually'), srCertificateTypeSetting::GENERATION_MANUAL);
             $input->addOption($option);
             $input->setValue($this->setting->getValue());
             break;
         case srCertificateTypeSetting::IDENTIFIER_VALIDITY_TYPE:
             $input = new ilRadioGroupInputGUI($title, $name);
             $option = new ilRadioOption($this->pl->txt('always'), srCertificateTypeSetting::VALIDITY_TYPE_ALWAYS);
             $input->addOption($option);
             $option = new ilRadioOption($this->pl->txt('setting_validity_range'), srCertificateTypeSetting::VALIDITY_TYPE_DATE_RANGE);
             $input->addOption($option);
             $option = new ilRadioOption($this->pl->txt('setting_validity_date'), srCertificateTypeSetting::VALIDITY_TYPE_DATE);
             $input->addOption($option);
             $input->setValue($this->setting->getValue());
             break;
         case srCertificateTypeSetting::IDENTIFIER_VALIDITY:
             $validity_value = $this->setting->getValue();
             switch ($this->type->getSettingByIdentifier(srCertificateTypeSetting::IDENTIFIER_VALIDITY_TYPE)->getValue()) {
                 case srCertificateTypeSetting::VALIDITY_TYPE_DATE_RANGE:
                     $input = new ilDurationInputGUI($title, $name);
                     $input->setShowMinutes(false);
                     $input->setShowHours(false);
                     $input->setShowDays(true);
                     $input->setShowMonths(true);
                     if ($validity_value) {
                         $range_array = json_decode($validity_value, true);
                         $data = array();
                         $data[$input->getPostVar()]['MM'] = $range_array['m'];
                         $data[$input->getPostVar()]['dd'] = $range_array['d'];
                         $input->setValueByArray($data);
                     }
                     break;
                 case srCertificateTypeSetting::VALIDITY_TYPE_DATE:
                     $input = new ilDateTimeInputGUI($title, $name);
                     $input->setMode(ilDateTimeInputGUI::MODE_INPUT);
                     if ($validity_value) {
                         $input->setDate(new ilDateTime($validity_value, IL_CAL_DATE));
                     }
                     break;
                 case srCertificateTypeSetting::VALIDITY_TYPE_ALWAYS:
                     // Makes no sence to configure this further
                     $input = null;
                     break;
                 default:
                     $input = new ilTextInputGUI($title, $name);
             }
             break;
         case srCertificateTypeSetting::IDENTIFIER_DOWNLOADABLE:
         case srCertificateTypeSetting::IDENTIFIER_SCORM_TIMING:
         case srCertificateTypeSetting::IDENTIFIER_NOTIFICATION_USER:
             $input = new ilCheckboxInputGUI($title, $name);
             if ($this->setting->getValue()) {
                 $input->setChecked(true);
             }
             break;
         default:
             $input = new ilTextInputGUI($title, $name);
             $input->setValue($this->setting->getValue());
     }
     return $input;
 }