コード例 #1
0
 function assignToSmarty($smarty)
 {
     $formRenderer = new HTML_QuickForm_Renderer_ArraySmarty($smarty);
     $formRenderer->setErrorTemplate('{if $error}<span class="cls-form-error" style="color: red; font-size: 0.7em;">{$error}</span><br/>{/if}{$html}');
     $this->accept($formRenderer);
     $smarty->assign($this->name . "_form_data", $formRenderer->toArray());
 }
コード例 #2
0
function prepareFormRenderer($form)
{
    $form->setJsWarnings(_BEFOREJAVASCRIPTERROR, _AFTERJAVASCRIPTERROR);
    $form->setRequiredNote(_REQUIREDNOTE);
    $renderer = new HTML_QuickForm_Renderer_ArraySmarty($GLOBALS['smarty']);
    $renderer->setRequiredTemplate('{$html}{if $required}
		            &nbsp;<span class = "formRequired">*</span>
		        {/if}');
    $renderer->setErrorTemplate('{$html}{if $error}
		            <span class = "formError">{$error}</span>
		        {/if}');
    $form->accept($renderer);
    return $renderer;
}
コード例 #3
0
ファイル: Form.php プロジェクト: rk4an/centreon
 /**
  * 
  * @param array $smartyArray
  */
 private function formatForSmarty()
 {
     $smartyArray = $this->formRenderer->toArray();
     $finalArray = array('frozen' => $smartyArray['frozen'], 'javascript' => $smartyArray['javascript'], 'attributes' => $smartyArray['attributes'], 'requirednote' => $smartyArray['requirednote'], 'errors' => $smartyArray['errors'], 'hidden' => $smartyArray['hidden']);
     if ($this->eventValidation['formId'] === '') {
         $this->eventValidation['formId'] = $this->formName;
     }
     if (isset($smartyArray['elements'])) {
         foreach ($smartyArray['elements'] as $element) {
             $finalArray[$element['name']] = array();
             foreach ($element as $key => $value) {
                 $finalArray[$element['name']][$key] = $value;
             }
             $this->renderAsHtml($finalArray[$element['name']]);
         }
     }
     return $finalArray;
 }
コード例 #4
0
                } elseif ($pathParts['extension'] == 'js') {
                    //do not create unit for js files
                } else {
                    if (file_exists(G_THEMESPATH . 'default/images/file_types/' . $pathParts['extension'] . '.png')) {
                        $fields['data'] = '<a href = "view_file.php?file=' . $file['id'] . '&action=download"><img src="images/file_types/' . $pathParts['extension'] . '.png" style="vertical-align:middle" />' . eFront_basename($file['name']) . '</a>';
                    } else {
                        $fields['data'] = '<a href = "view_file.php?file=' . $file['id'] . '&action=download">' . eFront_basename($file['name']) . '</a>';
                    }
                    $unit = $currentContent->insertNode($fields);
                }
            }
        }
        $message = _FILESIMPORTEDSUCCESSFULLY;
        $message_type = 'success';
    } catch (Exception $e) {
        handleNormalFlowExceptions($e);
    }
}
$form->setJsWarnings(_BEFOREJAVASCRIPTERROR, _AFTERJAVASCRIPTERROR);
$form->setRequiredNote(_REQUIREDNOTE);
$renderer = new HTML_QuickForm_Renderer_ArraySmarty($smarty);
$renderer->setRequiredTemplate('{$html}{if $required}
            &nbsp;<span class = "formRequired">*</span>
        {/if}');
$renderer->setErrorTemplate('{$html}{if $error}
            <span class = "formError">{$error}</span>
        {/if}');
$form->accept($renderer);
$smarty->assign("T_MAX_FILE_SIZE", FileSystemTree::getUploadMaxSize());
$smarty->assign('T_ENTITY_FORM', $renderer->toArray());
#cpp#endif
コード例 #5
0
        $form->addElement('advcheckbox', 'maximize_viewport', _MAXIMIZEVIEWABLEAREA, null, 'class = "inputCheckbox"', array(0, 1));
        $form->addElement('static', null, _SCORMSPECIFICPROPERTIES);
        $form->addElement('text', 'object_ids', _SPECIFYIDFORSREENMATCHING, 'class = "inputText"');
        $form->addElement('advcheckbox', 'no_before_unload', _NOBEFOREUPLOAD, null, 'class = "inputCheckbox"', array(0, 1));
        $form->addElement('advcheckbox', 'scorm_asynchronous', _SCORMASYNCHROUNOUS, null, 'class = "inputCheckbox"', array(0, 1));
        $form->addElement('text', 'scorm_times', _SCORMTIMES, 'class = "inputText" style = "width:50px"');
        $form->addElement('advcheckbox', 'scorm_logging', _SCORMLOGGING, null, 'class = "inputText"');
        $form->addElement('text', 'scorm_size', _EXPLICITIFRAMESIZE, 'class = "inputText" style = "width:50px"');
        //Set an explicit size for the SCORM content
        $form->addElement('select', 'reentry_action', _ACTIONONRENTRYCOMPLETED, array(0 => _LETCONTENTDECIDE, 1 => _DONTCHANGE), 'class = "inputText"');
        //Set what action should be performed when a user re-enters a visited content
        $form->addElement('select', 'embed_type', _EMBEDTYPE, array('iframe' => _INLINEIFRAME, 'popup' => _NEWWINDOWPOPUP), 'class = "inputSelect"');
        $form->addElement('text', 'popup_parameters', _POPUPPARAMETERS, 'class = "inputText" style = "width:600px"');
        $form->setJsWarnings(_BEFOREJAVASCRIPTERROR, _AFTERJAVASCRIPTERROR);
        $form->setRequiredNote(_REQUIREDNOTE);
        $renderer = new HTML_QuickForm_Renderer_ArraySmarty($smarty);
        $renderer->setErrorTemplate('{$html}{if $error}
	            <span class = "formError">{$error}</span>
	        {/if}');
        $form->accept($renderer);
        $smarty->assign('T_ENTITY_FORM', $renderer->toArray());
        if (isset($_GET['ajax'])) {
            try {
                $basicIterator = new EfrontNodeFilterIterator(new RecursiveIteratorIterator(new RecursiveArrayIterator($currentContent->tree), RecursiveIteratorIterator::SELF_FIRST));
                foreach (new EfrontNoSCORMFilterIterator(new EfrontNoFeedbackFilterIterator(new EfrontNoTestsFilterIterator($basicIterator))) as $key => $value) {
                    if (!$_GET['scorm']) {
                        if ($_GET['option'] == 'ctg_type') {
                            $value['ctg_type'] = $_GET['value'];
                        } else {
                            $value['options'][$_GET['option']] = $_GET['value'];
                        }
コード例 #6
0
 /**
  * Creates an array representing an element containing
  * the key for storing this. We allow the parent to do most of the
  * work, but then we add some CiviCRM specific enhancements to 
  * make the html compliant with our css etc
  *
  * @access private
  * @param  object    An HTML_QuickForm_element object
  * @param  bool      Whether an element is required
  * @param  string    Error associated with the element
  * @return array
  */
 function _elementToArray(&$element, $required, $error)
 {
     CRM_Core_Form_Renderer::updateAttributes($element, $required, $error);
     $el = parent::_elementToArray($element, $required, $error);
     // add label html
     if (!empty($el['label'])) {
         $id = $element->getAttribute('id');
         if (!empty($id)) {
             $el['label'] = '<label for="' . $id . '">' . $el['label'] . '</label>';
         }
     }
     return $el;
 }
コード例 #7
0
ファイル: Renderer.php プロジェクト: kidaa30/yes
 /**
  * Creates an array representing an element containing.
  * the key for storing this. We allow the parent to do most of the
  * work, but then we add some CiviCRM specific enhancements to
  * make the html compliant with our css etc
  *
  *
  * @param HTML_QuickForm_element $element
  * @param bool $required
  *   Whether an element is required.
  * @param string $error
  *   Error associated with the element.
  *
  * @return array
  */
 public function _elementToArray(&$element, $required, $error)
 {
     self::updateAttributes($element, $required, $error);
     $el = parent::_elementToArray($element, $required, $error);
     // add label html
     if (!empty($el['label'])) {
         $id = $element->getAttribute('id');
         if (!empty($id)) {
             $el['label'] = '<label for="' . $id . '">' . $el['label'] . '</label>';
         } else {
             $el['label'] = "<label>{$el['label']}</label>";
         }
     }
     // Display-only (frozen) elements
     if (!empty($el['frozen'])) {
         if ($element->getAttribute('data-api-entity') && $element->getAttribute('data-entity-value')) {
             $this->renderFrozenEntityRef($el, $element);
         }
         $el['html'] = '<span class="crm-frozen-field">' . $el['html'] . '</span>';
     } else {
         if ($element->getType() == 'select' && $element->getAttribute('data-option-edit-path')) {
             $this->addOptionsEditLink($el, $element);
         }
         if ($element->getType() == 'group' && $element->getAttribute('allowClear')) {
             $this->appendUnselectButton($el, $element);
         }
     }
     return $el;
 }
コード例 #8
0
 public function getSmartyTpl()
 {
     $smarty = $this->getSmartyVar();
     $currentUser = $this->getCurrentUser();
     $currentLesson = $this->getCurrentLesson();
     $currentLessonID = $currentLesson->lesson['id'];
     if ($currentUser->getRole($this->getCurrentLesson()) == 'professor' || $currentUser->getRole($this->getCurrentLesson()) == 'student') {
         // XXX
         $workbookLessonName = _WORKBOOK_NAME . ' [' . $this->getWorkbookLessonName($currentLessonID) . ']';
         $smarty->assign("T_WORKBOOK_LESSON_NAME", $workbookLessonName);
         $lessonQuestions = $this->getLessonQuestions($currentLessonID);
         $workbookLessons = $this->isWorkbookInstalledByUser($currentUser, $currentUser->getRole($this->getCurrentLesson()), $currentLessonID);
         $workbookItems = $this->getWorkbookItems($currentLessonID);
         $nonOptionalQuestionsNr = $this->getNonOptionalQuestionsNr($workbookItems);
         if ($nonOptionalQuestionsNr != 0) {
             $questionPercentage = (double) (100 / $nonOptionalQuestionsNr);
             $questionPercentage = round($questionPercentage, 2);
         }
         $isWorkbookPublished = $this->isWorkbookPublished($currentLessonID);
     }
     if ($currentUser->getRole($this->getCurrentLesson()) == 'student') {
         $workbookSettings = $this->getWorkbookSettings($currentLessonID);
         $smarty->assign("T_WORKBOOK_SETTINGS", $workbookSettings);
     }
     $smarty->assign("T_WORKBOOK_BASEURL", $this->moduleBaseUrl);
     $smarty->assign("T_WORKBOOK_BASELINK", $this->moduleBaseLink);
     global $popup;
     isset($popup) && $popup == 1 ? $popup_ = '&popup=1' : ($popup_ = '');
     if (isset($_REQUEST['question_preview']) && $_REQUEST['question_preview'] == '1' && isset($_REQUEST['question_id']) && eF_checkParameter($_REQUEST['question_id'], 'id')) {
         $id = $_REQUEST['question_id'];
         if (!in_array($id, array_keys($lessonQuestions))) {
             // reused item
             $reusedQuestion = $this->getReusedQuestionDetails($id);
             $type = $reusedQuestion['type'];
         } else {
             $type = $lessonQuestions[$id]['type'];
         }
         echo $this->questionToHtml($id, $type);
         exit;
     }
     if (isset($_REQUEST['get_progress']) && $_REQUEST['get_progress'] == '1') {
         $isWorkbookCompleted = $this->isWorkbookCompleted($currentUser->user['login'], $currentLessonID, array_keys($workbookItems), $nonOptionalQuestionsNr);
         $studentProgress = $this->getStudentProgress($currentUser->user['login'], $currentLessonID);
         if ($isWorkbookCompleted['is_completed'] == 1) {
             $unitToComplete = $workbookSettings['unit_to_complete'];
             $result = eF_updateTableData('module_workbook_progress', array('completion_date' => time()), "lessons_ID='" . $currentLessonID . "' AND users_LOGIN='******'login'] . "'");
             if ($unitToComplete != -1) {
                 $currentUser->setSeenUnit($unitToComplete, $currentLessonID, true);
             }
         }
         echo $studentProgress . '-' . $isWorkbookCompleted['id'];
         exit;
     }
     if (isset($_GET['edit_settings']) && $_GET['edit_settings'] == '1') {
         if ($_SESSION['s_type'] != 'professor') {
             $message = _WORKBOOK_NOACCESS;
             $message_type = 'failure';
             $this->setMessageVar(urlencode($message), $message_type);
         }
         $content = new EfrontContentTree($currentLessonID);
         $iterator = new EfrontNodeFilterIterator(new RecursiveIteratorIterator(new RecursiveArrayIterator($content->tree), RecursiveIteratorIterator::SELF_FIRST), array('ctg_type' => 'theory'));
         $contentOptions = $content->toHTMLSelectOptions($iterator);
         $contentOptions = array(-1 => '-------------') + $contentOptions;
         $workbookSettings = $this->getWorkbookSettings($currentLessonID);
         if ($isWorkbookPublished == 1) {
             $contentOptions[$workbookSettings['unit_to_complete']] = str_replace('&nbsp;', '', $contentOptions[$workbookSettings['unit_to_complete']]);
             $contentOptions[$workbookSettings['unit_to_complete']] = str_replace('&raquo;', '', $contentOptions[$workbookSettings['unit_to_complete']]);
         }
         $form = new HTML_QuickForm("edit_settings_form", "post", $this->moduleBaseUrl . "&edit_settings=1", "", null, true);
         $form->addElement('text', 'lesson_name', _WORKBOOK_LESSON_NAME, 'class="inputText"');
         $form->addRule('lesson_name', _THEFIELD . ' "' . _WORKBOOK_LESSON_NAME . '" ' . _ISMANDATORY, 'required', null, 'client');
         $form->addElement('advcheckbox', 'allow_print', _WORKBOOK_ALLOW_PRINT, null, 'class="inputCheckBox"', array(0, 1));
         $form->addElement('advcheckbox', 'allow_export', _WORKBOOK_ALLOW_EXPORT, null, 'class="inputCheckBox"', array(0, 1));
         $form->addElement('advcheckbox', 'edit_answers', _WORKBOOK_EDIT_ANSWERS, null, 'class="inputCheckBox"', array(0, 1));
         $form->addElement('select', 'unit_to_complete', _WORKBOOK_UNIT_TO_COMPLETE, $contentOptions);
         $form->addElement('submit', 'submit', _UPDATE, 'class="flatButton"');
         if ($isWorkbookPublished == 1) {
             $form->freeze('unit_to_complete');
         }
         $form->setDefaults($workbookSettings);
         if ($form->isSubmitted() && $form->validate()) {
             $values = $form->exportValues();
             $fields = array("lesson_name" => $values['lesson_name'], "allow_print" => $values['allow_print'], "allow_export" => $values['allow_export'], "edit_answers" => $values['edit_answers'], "unit_to_complete" => $values['unit_to_complete']);
             if (eF_updateTableData("module_workbook_settings", $fields, "id=" . $workbookSettings['id'])) {
                 $smarty->assign("T_WORKBOOK_MESSAGE", _WORKBOOK_SETTINGS_SUCCESSFULLY_EDITED);
                 $smarty->assign("T_WORKBOOK_MESSAGE_TYPE", 'success');
             } else {
                 $smarty->assign("T_WORKBOOK_MESSAGE", _WORKBOOK_SETTINGS_EDIT_PROBLEM);
                 $smarty->assign("T_WORKBOOK_MESSAGE_TYPE", 'failure');
             }
         }
         $renderer = new HTML_QuickForm_Renderer_ArraySmarty($smarty);
         $renderer->setRequiredTemplate('{$html}{if $required}&nbsp;<span class="formRequired">*</span>{/if}');
         $form->setJsWarnings(_BEFOREJAVASCRIPTERROR, _AFTERJAVASCRIPTERROR);
         $form->setRequiredNote(_REQUIREDNOTE);
         $form->accept($renderer);
         $smarty->assign('T_WORKBOOK_EDIT_SETTINGS_FORM', $renderer->toArray());
     }
     if (isset($_GET['reuse_item']) && $_GET['reuse_item'] == '1') {
         if ($_SESSION['s_type'] != 'professor') {
             $message = _WORKBOOK_NOACCESS;
             $message_type = 'failure';
             $this->setMessageVar(urlencode($message), $message_type);
         }
         $form = new HTML_QuickForm("reuse_item_form", "post", $this->moduleBaseUrl . "&reuse_item=1", "", null, true);
         $form->addElement('text', 'item_id', _WORKBOOK_ITEM_ID, 'class="inputText"');
         $form->addRule('item_id', _THEFIELD . ' "' . _WORKBOOK_ITEM_ID . '" ' . _ISMANDATORY, 'required', null, 'client');
         $form->addElement('submit', 'submit', _WORKBOOK_REUSE_ITEM, 'class="flatButton"');
         if ($form->isSubmitted() && $form->validate()) {
             $values = $form->exportValues();
             $existingIDs = $this->getItemsUniqueIDs();
             if (!in_array($values['item_id'], $existingIDs)) {
                 $message = _WORKBOOK_INVALID_UNIQUE_ID;
                 $message_type = 'failure';
                 $this->setMessageVar(urlencode($message), $message_type);
             } else {
                 $item = $this->getItemByUniqueID($values['item_id']);
                 $fields = array("item_title" => $item['item_title'], "item_text" => $item['item_text'], "item_question" => $item['item_question'], "question_text" => $item['question_text'], "check_answer" => $item['check_answer'], "lessons_ID" => $currentLessonID, "unique_ID" => $this->generateItemID(), "position" => $this->itemPosition($currentLessonID));
                 if (eF_insertTableData("module_workbook_items", $fields)) {
                     $smarty->assign("T_WORKBOOK_MESSAGE", urlencode(_WORKBOOK_ITEM_SUCCESSFULLY_ADDED));
                     $smarty->assign("T_WORKBOOK_MESSAGE_TYPE", 'success');
                 } else {
                     $smarty->assign("T_WORKBOOK_MESSAGE", _WORKBOOK_ITEM_ADD_PROBLEM);
                     $smarty->assign("T_WORKBOOK_MESSAGE_TYPE", 'failure');
                 }
             }
         }
         $renderer = new HTML_QuickForm_Renderer_ArraySmarty($smarty);
         $renderer->setRequiredTemplate('{$html}{if $required}&nbsp;<span class="formRequired">*</span>{/if}');
         $form->setJsWarnings(_BEFOREJAVASCRIPTERROR, _AFTERJAVASCRIPTERROR);
         $form->setRequiredNote(_REQUIREDNOTE);
         $form->accept($renderer);
         $smarty->assign('T_WORKBOOK_REUSE_ITEM_FORM', $renderer->toArray());
     }
     if (isset($_GET['move_item']) && eF_checkParameter($_GET['move_item'], 'id') && in_array($_GET['move_item'], array_keys($workbookItems))) {
         if ($_SESSION['s_type'] != 'professor') {
             $message = _WORKBOOK_NOACCESS;
             $message_type = 'failure';
             $this->setMessageVar(urlencode($message), $message_type);
         }
         $smarty->assign("T_WORKBOOK_ITEMS_COUNT", count($workbookItems));
         $itemPosition = $workbookItems[$_GET['move_item']]['position'];
         $availablePositions = array();
         foreach ($workbookItems as $key => $value) {
             if ($value['position'] != $itemPosition) {
                 $availablePositions[$value['position']] = $value['position'];
             }
         }
         $form = new HTML_QuickForm("move_item_form", "post", $this->moduleBaseUrl . "&move_item=" . $_GET['move_item'], "", null, true);
         $form->addElement('select', 'item_position', _WORKBOOK_ITEM_NEW_POSITION, $availablePositions, '');
         $form->addElement('submit', 'submit', _WORKBOOK_MOVE_ITEM, 'class="flatButton"');
         if ($form->isSubmitted() && $form->validate()) {
             $values = $form->exportValues();
             $newPosition = $values['item_position'];
             if ($newPosition > $itemPosition) {
                 foreach ($workbookItems as $key => $value) {
                     if ($value['position'] > $itemPosition && $value['position'] <= $newPosition) {
                         eF_updateTableData("module_workbook_items", array('position' => $value['position'] - 1), "id=" . $key);
                     }
                 }
             } else {
                 foreach ($workbookItems as $key => $value) {
                     if ($value['position'] < $itemPosition && $value['position'] >= $newPosition) {
                         eF_updateTableData("module_workbook_items", array('position' => $value['position'] + 1), "id=" . $key);
                     }
                 }
             }
             eF_updateTableData("module_workbook_items", array('position' => $newPosition), "id=" . $_GET['move_item']);
             $smarty->assign("T_WORKBOOK_MESSAGE", _WORKBOOK_ITEM_SUCCESSFULLY_MOVED);
             $smarty->assign("T_WORKBOOK_MESSAGE_TYPE", 'success');
         }
         $renderer = new HTML_QuickForm_Renderer_ArraySmarty($smarty);
         $renderer->setRequiredTemplate('{$html}{if $required}&nbsp;<span class="formRequired">*</span>{/if}');
         $form->setJsWarnings(_BEFOREJAVASCRIPTERROR, _AFTERJAVASCRIPTERROR);
         $form->setRequiredNote(_REQUIREDNOTE);
         $form->accept($renderer);
         $smarty->assign('T_WORKBOOK_MOVE_ITEM_FORM', $renderer->toArray());
     }
     if (isset($_GET['delete_item']) && eF_checkParameter($_GET['delete_item'], 'id') && in_array($_GET['delete_item'], array_keys($workbookItems))) {
         $item_id = $_GET['delete_item'];
         $itemPosition = $workbookItems[$item_id]['position'];
         foreach ($workbookItems as $key => $value) {
             if ($value['position'] > $itemPosition) {
                 eF_updateTableData("module_workbook_items", array('position' => $value['position'] - 1), "id=" . $key);
             }
         }
         eF_deleteTableData("module_workbook_items", "id=" . $item_id);
     }
     if (isset($_GET['switch_lesson']) && eF_checkParameter($_GET['switch_lesson'], 'id') && in_array($_GET['switch_lesson'], array_keys($workbookLessons))) {
         $lessonID = $_GET['switch_lesson'];
         eF_redirect("location:" . $this->moduleBaseUrl . "&lessons_ID=" . $lessonID . $popup_);
     }
     if (isset($_GET['add_item']) && $_GET['add_item'] == '1' || isset($_GET['edit_item']) && eF_checkParameter($_GET['edit_item'], 'id') && in_array($_GET['edit_item'], array_keys($workbookItems))) {
         if ($_SESSION['s_type'] != "professor") {
             eF_redirect($this->moduleBaseUrl . "&message=" . urlencode(_WORKBOOK_NOACCESS) . $popup_);
         }
         global $load_editor;
         $load_editor = true;
         $questionsText = array();
         $questionsText[-1] = "-----------------------";
         foreach ($lessonQuestions as $key => $value) {
             $questionsText[$key] = $this->truncateText(strip_tags($value['text']), 70);
         }
         if (isset($_GET['edit_item'])) {
             $editItemID = $_GET['edit_item'];
             $editItemQuestion = $workbookItems[$editItemID]['item_question'];
             if ($editItemQuestion != '-1' && !in_array($editItemQuestion, array_keys($questionsText))) {
                 // reused item
                 $reusedQuestion = $this->getReusedQuestionDetails($editItemQuestion);
                 $questionsText[$editItemQuestion] = $this->truncateText(strip_tags($reusedQuestion['text']), 70);
             }
         }
         isset($_GET['add_item']) ? $postTarget = "&add_item=1" : ($postTarget = "&edit_item=" . $_GET['edit_item']);
         $form = new HTML_QuickForm("add_edit_item_form", "post", $this->moduleBaseUrl . $postTarget, "", null, true);
         $form->addElement('text', 'item_title', _WORKBOOK_ITEM_TITLE, 'class="inputText" style="width:500px;"');
         $form->addElement('textarea', 'item_text', _WORKBOOK_ITEM_TEXT, 'class="mceEditor" style="width:99%;height:300px;" id="editor_content_data"');
         $form->addElement('select', 'item_question', _WORKBOOK_ITEM_QUESTION, $questionsText, 'onchange="questionPreview(this)"');
         $form->addElement('advcheckbox', 'check_answer', _WORKBOOK_ITEM_GRADE_ANSWER, null, 'class="inputCheckBox"', array(0, 1));
         if (isset($_GET['add_item'])) {
             $form->addElement('submit', 'submit', _WORKBOOK_ADD_ITEM, 'class="flatButton"');
         } else {
             $form->addElement('submit', 'submit', _WORKBOOK_UPDATE_ITEM, 'class="flatButton"');
         }
         if (isset($_GET['edit_item'])) {
             $editItem = $workbookItems[$_GET['edit_item']];
             $form->setDefaults($editItem);
             if ($isWorkbookPublished == '1') {
                 $editItem['question_title'] = $questionsText[$editItem['item_question']];
                 if ($editItem['check_answer'] == '1') {
                     $editItem['check_answer_text'] = _YES;
                 } else {
                     $editItem['check_answer_text'] = _NO;
                 }
             }
             $smarty->assign('T_WORKBOOK_EDIT_ITEM_DETAILS', $editItem);
         }
         if ($form->isSubmitted() && $form->validate()) {
             $values = $form->exportValues();
             isset($_GET['add_item']) ? $lessonID = $currentLessonID : ($lessonID = $editItem['lessons_ID']);
             isset($_GET['add_item']) ? $uniqueID = $this->generateItemID() : ($uniqueID = $editItem['unique_ID']);
             isset($_GET['add_item']) ? $position = $this->itemPosition($currentLessonID) : ($position = $editItem['position']);
             if ($values['item_question'] != '-1') {
                 $id = $values['item_question'];
                 if (!in_array($id, array_keys($lessonQuestions))) {
                     // edit reused item
                     $reusedQuestion = $this->getReusedQuestionDetails($id);
                     $type = $reusedQuestion['type'];
                 } else {
                     $type = $lessonQuestions[$id]['type'];
                 }
                 $questionText = $this->questionToHtml($id, $type);
             } else {
                 $questionText = '';
             }
             $fields = array("item_title" => $values['item_title'], "item_text" => $values['item_text'], "item_question" => $values['item_question'], "question_text" => $questionText, "check_answer" => $values['check_answer'], "lessons_ID" => $lessonID, "unique_ID" => $uniqueID, "position" => $position);
             if ($values['item_title'] == '' && $values['item_text'] == '' && $values['item_question'] == '-1') {
                 $message = _WORKBOOK_ITEM_EMPTY_FIELDS;
                 if (isset($_GET['add_item'])) {
                     eF_redirect($this->moduleBaseUrl . "&message=" . urlencode($message) . "&message_type=failure&add_item=1" . $popup_);
                 } else {
                     $itemID = $_GET['edit_item'];
                     eF_redirect($this->moduleBaseUrl . "&message=" . urlencode($message) . "&message_type=failure&edit_item=" . $itemID . $popup_);
                 }
             }
             if (isset($_GET['add_item'])) {
                 if (eF_insertTableData("module_workbook_items", $fields)) {
                     $message = _WORKBOOK_ITEM_SUCCESSFULLY_ADDED;
                     eF_redirect($this->moduleBaseUrl . "&message=" . urlencode($message) . "&message_type=success" . $popup_);
                 } else {
                     $message = _WORKBOOK_ITEM_ADD_PROBLEM;
                     eF_redirect($this->moduleBaseUrl . "&message=" . urlencode($message) . "&message_type=failure" . $popup_);
                 }
             } else {
                 if (eF_updateTableData("module_workbook_items", $fields, "id=" . $_GET['edit_item'])) {
                     $message = _WORKBOOK_ITEM_SUCCESSFULLY_EDITED;
                     eF_redirect($this->moduleBaseUrl . "&message=" . urlencode($message) . "&message_type=success" . $popup_);
                 } else {
                     $message = _WORKBOOK_ITEM_EDIT_PROBLEM;
                     eF_redirect($this->moduleBaseUrl . "&message=" . urlencode($message) . "&message_type=failure" . $popup_);
                 }
             }
         }
         $renderer = new HTML_QuickForm_Renderer_ArraySmarty($smarty);
         $form->setJsWarnings(_BEFOREJAVASCRIPTERROR, _AFTERJAVASCRIPTERROR);
         $form->setRequiredNote(_REQUIREDNOTE);
         $form->accept($renderer);
         $smarty->assign('T_WORKBOOK_ADD_EDIT_ITEM_FORM', $renderer->toArray());
         $basedir = $currentLesson->getDirectory();
         $options = array('lessons_ID' => $currentLessonID, 'metadata' => 0);
         $url = $_SERVER['REQUEST_URI'];
         $extraFileTools = array(array('image' => 'images/16x16/arrow_right.png', 'title' => _INSERTEDITOR, 'action' => 'insert_editor'));
         include "file_manager.php";
     }
     if (isset($_GET['publish_workbook']) && $_GET['publish_workbook'] == '1') {
         $result = eF_getTableData("module_workbook_publish", "publish", "lessons_ID=" . $currentLessonID);
         if (count($result) == 0) {
             if (eF_insertTableData("module_workbook_publish", array('lessons_ID' => $currentLessonID, 'publish' => 1))) {
                 $message = _WORKBOOK_SUCCESSFULLY_PUBLISHED;
                 eF_redirect($this->moduleBaseUrl . "&message=" . urlencode($message) . "&message_type=success" . $popup_);
             } else {
                 $message = _WORKBOOK_PUBLISH_PROBLEM;
                 eF_redirect($this->moduleBaseUrl . "&message=" . urlencode($message) . "&message_type=failure" . $popup_);
             }
         } else {
             if (eF_updateTableData("module_workbook_publish", array('publish' => 1), "lessons_ID=" . $currentLessonID)) {
                 $message = _WORKBOOK_SUCCESSFULLY_PUBLISHED;
                 eF_redirect($this->moduleBaseUrl . "&message=" . urlencode($message) . "&message_type=success" . $popup_);
             } else {
                 $message = _WORKBOOK_PUBLISH_PROBLEM;
                 eF_redirect($this->moduleBaseUrl . "&message=" . urlencode($message) . "&message_type=failure" . $popup_);
             }
         }
     }
     if (isset($_GET['reset_workbook_professor']) && $_GET['reset_workbook_professor'] == '1') {
         eF_updateTableData("module_workbook_publish", array('publish' => 0), "lessons_ID=" . $currentLessonID);
         foreach ($workbookItems as $key => $value) {
             eF_deleteTableData("module_workbook_answers", "item_id=" . $key);
             eF_deleteTableData("module_workbook_autosave", "item_id=" . $key);
             eF_deleteTableData("module_workbook_progress", "lessons_ID=" . $currentLessonID);
         }
     }
     if (isset($_GET['reset_workbook_student']) && eF_checkParameter($_GET['reset_workbook_student'], 'id')) {
         $id = $_GET['reset_workbook_student'];
         $result = eF_getTableData("module_workbook_progress", "users_LOGIN", "id=" . $id);
         if ($result[0]['users_LOGIN'] != $currentUser->user['login']) {
             eF_redirect($this->moduleBaseUrl . "&message=" . urlencode(_WORKBOOK_NOACCESS) . $popup_);
         }
         eF_deleteTableData("module_workbook_progress", "id=" . $id);
         foreach ($workbookItems as $key => $value) {
             eF_deleteTableData("module_workbook_answers", "item_id=" . $key . " AND users_LOGIN='******'login'] . "'");
         }
         $unitToComplete = $workbookSettings['unit_to_complete'];
         if ($unitToComplete != -1) {
             $currentUser->setSeenUnit($unitToComplete, $currentLessonID, false);
         }
     }
     if (isset($_GET['download_as']) && $_GET['download_as'] == 'doc') {
         include dirname(__FILE__) . "/classes/html_to_doc.inc.php";
         $workbookAnswers = $this->getWorkbookAnswers($currentUser->user['login'], array_keys($workbookItems));
         $workbookHTML = '';
         foreach ($workbookItems as $key => $value) {
             $workbookHTML .= '<div style="width:98%;float:left;border:1px dotted #808080;padding: 5px 10px;">';
             $workbookHTML .= '<div style="background-color: #EAEAEA;border: 1px solid #AAAAAA;padding: 2px;font-weight: bold;">';
             $workbookHTML .= _WORKBOOK_ITEMS_COUNT . $value['position'];
             if ($value['item_title'] != '') {
                 $workbookHTML .= '&nbsp;-&nbsp;' . $value['item_title'];
             }
             $workbookHTML .= '</div><br/>';
             if ($value['item_text'] != '') {
                 $workbookHTML .= '<div>' . $value['item_text'] . '</div><br/>';
             }
             if ($value['item_question'] != '-1') {
                 $questionType = $lessonQuestions[$value['item_question']]['type'];
                 if ($workbookAnswers[$value['id']] == '') {
                     if ($questionType == 'drag_drop') {
                         $dragDrop = eF_getTableData("questions", "options, answer, text", "id=" . $value['item_question']);
                         $options = unserialize($dragDrop[0]['options']);
                         $answer = unserialize($dragDrop[0]['answer']);
                         shuffle($options);
                         shuffle($answer);
                         $workbookHTML .= $dragDrop[0]['text'];
                         for ($i = 0; $i < count($options); $i++) {
                             $workbookHTML .= '<div>' . $options[$i] . '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
                             $workbookHTML .= $answer[$i] . '</div>';
                         }
                     } else {
                         $workbookHTML .= '<div>' . $value['question_text'] . '</div>';
                     }
                 } else {
                     $workbookHTML .= '<div>' . $workbookAnswers[$value['id']] . '</div>';
                 }
             }
             $workbookHTML .= '</div><br/>';
         }
         $workbookHTML = preg_replace('/<script\\b[^>]*>(.*?)<\\/script>/is', "", $workbookHTML);
         $fileName = _WORKBOOK_NAME . '_' . $this->getWorkbookLessonName($currentLessonID);
         $fileName = preg_replace('/[\\s]+/', '_', $fileName);
         $htmltodoc = new HTML_TO_DOC();
         $htmltodoc->createDoc($workbookHTML, $fileName, true);
         exit(0);
     }
     if (isset($_GET['download_as']) && $_GET['download_as'] == 'pdf') {
         $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true);
         $pdf->SetCreator(PDF_CREATOR);
         $pdf->SetAuthor(PDF_AUTHOR);
         $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
         $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
         $pdf->setFontSubsetting(false);
         $pdf->AddPage();
         $completion_date = '';
         $resutlt = eF_getTableData('module_workbook_progress', 'completion_date', "users_LOGIN='******'login'] . "' and lessons_ID='" . $currentLessonID . "'");
         if ($resutlt) {
             $completion_date = $resutlt[0]['completion_date'];
         }
         $workbookHTML = '';
         $workbookHTML .= '<table>';
         $workbookHTML .= '<tr>';
         $workbookHTML .= '<td colspan="2">';
         $workbookHTML .= formatLogin($currentUser->user['login']);
         $workbookHTML .= '</td>';
         $workbookHTML .= '</tr>';
         $workbookHTML .= '<tr>';
         $workbookHTML .= '<td>';
         $workbookHTML .= $workbookLessonName;
         $workbookHTML .= '</td>';
         $workbookHTML .= '<td>';
         $workbookHTML .= formatTimestamp($completion_date);
         $workbookHTML .= '</td>';
         $workbookHTML .= '</tr>';
         $workbookHTML .= '</table>';
         $pdf->writeHTML($workbookHTML, true, false, true, false, '');
         $pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
         $pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
         $pdf->setHeaderFont(array('Freeserif', 'I', 11));
         $pdf->setFooterFont(array('Freeserif', '', 8));
         $pdf->setHeaderData('', '', '', $workbookLessonName);
         $pdf->AliasNbPages();
         $pdf->SetFont('Freeserif', '', 10);
         $pdf->SetTextColor(0, 0, 0);
         $pdf->SetFont('Freeserif', '', 10);
         $pdf->SetTextColor(0, 0, 0);
         $workbookAnswers = $this->getWorkbookAnswers($currentUser->user['login'], array_keys($workbookItems));
         $pdf->AddPage();
         $workbookHTML .= '';
         $itemLogo = new EfrontFile(G_DEFAULTIMAGESPATH . "32x32/unit.png");
         $itemLogoUrl = $itemLogo['path'];
         foreach ($workbookItems as $key => $value) {
             $workbookHTML .= '<div id="pdf-block" style="width:98%;float:left;border:1px dotted #808080;page-break-after:always;">';
             $workbookHTML .= '<div style="background-color: #EAEAEA;font-weight: bold;">';
             $workbookHTML .= '<img src="' . $itemLogoUrl . '"/>&nbsp;' . _WORKBOOK_ITEMS_COUNT . $value['position'];
             if ($value['item_title'] != '') {
                 $workbookHTML .= '&nbsp;-&nbsp;' . $value['item_title'];
             }
             $workbookHTML .= '</div>';
             if ($value['item_text'] != '') {
                 $workbookHTML .= '<div>' . $value['item_text'] . '</div>';
             }
             if ($value['item_question'] != '-1') {
                 $questionType = $lessonQuestions[$value['item_question']]['type'];
                 if ($workbookAnswers[$value['id']] == '') {
                     if ($questionType == 'drag_drop') {
                         $dragDrop = eF_getTableData("questions", "options, answer, text", "id=" . $value['item_question']);
                         $options = unserialize($dragDrop[0]['options']);
                         $answer = unserialize($dragDrop[0]['answer']);
                         shuffle($options);
                         shuffle($answer);
                         $workbookHTML .= $dragDrop[0]['text'];
                         for ($i = 0; $i < count($options); $i++) {
                             $workbookHTML .= '<div>' . $options[$i] . '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
                             $workbookHTML .= $answer[$i] . '</div>';
                         }
                     } else {
                         $workbookHTML .= '<div>' . $value['question_text'] . '</div>';
                     }
                 } else {
                     $workbookHTML .= '<div>' . $workbookAnswers[$value['id']] . '</div>';
                 }
             }
             $workbookHTML .= '</div><br/>';
         }
         $workbookHTML = preg_replace('/<script\\b[^>]*>(.*?)<\\/script>/is', "", $workbookHTML);
         $pdf->writeHTML($workbookHTML, true, false, true, false, '');
         $fileName = _WORKBOOK_NAME . '_' . str_replace(' ', '_', $this->getWorkbookLessonName($currentLessonID)) . '.pdf';
         header("Content-type: application/pdf");
         header("Content-disposition: attachment; filename=" . $fileName);
         echo $pdf->Output('', 'S');
         exit(0);
     }
     if (isset($_GET['check_workbook_progress']) && $_GET['check_workbook_progress'] == '1') {
         $lessonStudents = $currentLesson->getUsers('student');
         $workbookStudents = array();
         foreach ($lessonStudents as $userLogin => $value) {
             if ($nonOptionalQuestionsNr != 0) {
                 $studentProgress = $this->getStudentProgress($userLogin, $currentLessonID);
                 $studentProgress .= '%';
             } else {
                 $studentProgress = '-';
             }
             $workbookStudents[$userLogin] = array('login' => $userLogin, 'progress' => $studentProgress);
         }
         $smarty->assign("T_WORKBOOK_STUDENTS", $workbookStudents);
     }
     if (isset($_GET['preview_workbook']) && $_GET['preview_workbook'] == '1' && isset($_GET['student']) && eF_checkParameter($_GET['student'], 'login')) {
         $userLogin = $_GET['student'];
         $studentProgress = $this->getStudentProgress($userLogin, $currentLessonID);
         $smarty->assign("T_WORKBOOK_PREVIEW_STUDENT_PROGRESS", $studentProgress);
         $workbookAnswers = $this->getWorkbookAnswers($userLogin, array_keys($workbookItems));
         $smarty->assign("T_WORKBOOK_PREVIEW_ANSWERS", $workbookAnswers);
     }
     if (isset($_GET['get_reset_message']) && $_GET['get_reset_message'] == '1') {
         echo $this->getResetMessage(array_keys($workbookItems));
         exit;
     }
     if (isset($_POST['item_submitted'])) {
         $itemID = $_POST['item_submitted'];
         $questionID = $workbookItems[$itemID]['item_question'];
         $checkAnswer = $workbookItems[$itemID]['check_answer'];
         if (!in_array($questionID, array_keys($lessonQuestions))) {
             // reused item
             $reusedQuestion = $this->getReusedQuestionDetails($questionID);
             $questionType = $reusedQuestion['type'];
         } else {
             $questionType = $lessonQuestions[$questionID]['type'];
         }
         $question = QuestionFactory::factory($questionID);
         $question->setDone($_POST['question'][$questionID]);
         $results = $question->correct();
         if ($questionType != 'raw_text' && !ef_compare_float($results['score'], 1)) {
             print '-1';
         } else {
             $form = new HTML_QuickForm("questionForm", "post", "", "", null, true);
             $fields = array('item_id' => $itemID, 'html_solved' => $question->toHTMLSolved($form), 'users_LOGIN' => $currentUser->user['login']);
             eF_insertTableData("module_workbook_answers", $fields);
             if ($checkAnswer == '1') {
                 $this->updateStudentProgress($currentUser->user['login'], $currentLessonID, $questionPercentage, $nonOptionalQuestionsNr);
             }
             echo $question->toHTMLSolved($form);
         }
         eF_deleteTableData("module_workbook_autosave", "item_id=" . $itemID . " AND users_LOGIN='******'login'] . "'");
         exit(0);
     }
     if (isset($_POST['item_submitted_autosave'])) {
         $itemID = $_POST['item_submitted_autosave'];
         $questionID = $workbookItems[$itemID]['item_question'];
         $question = QuestionFactory::factory($questionID);
         $form = new HTML_QuickForm("questionForm", "post", "", "", null, true);
         $form->setDefaults($_POST);
         $fields = array('item_id' => $itemID, 'autosave_text' => $question->toHTML($form), 'users_LOGIN' => $currentUser->user['login']);
         eF_deleteTableData("module_workbook_autosave", "item_id=" . $itemID . " AND users_LOGIN='******'login'] . "'");
         eF_insertTableData("module_workbook_autosave", $fields);
         exit(0);
     }
     if (isset($_POST['item_to_update'])) {
         $itemID = $_POST['item_to_update'];
         $questionID = $workbookItems[$itemID]['item_question'];
         $question = QuestionFactory::factory($questionID);
         $question->userAnswer = urldecode($_POST['ans']);
         $form = new HTML_QuickForm("questionForm", "post", "", "", null, true);
         $form->setDefaults($_POST);
         print $question->toHTML($form);
         exit(0);
     }
     if (isset($_POST['item_updated'])) {
         $itemID = $_POST['item_updated'];
         $questionID = $workbookItems[$itemID]['item_question'];
         $question = QuestionFactory::factory($questionID);
         $question->setDone($_POST['question'][$questionID]);
         $form = new HTML_QuickForm("questionForm", "post", "", "", null, true);
         $answerToUpdate = eF_getTableData("module_workbook_answers", "id", "item_id=" . $itemID . " AND users_LOGIN='******'login'] . "'");
         eF_updateTableData("module_workbook_answers", array('html_solved' => $question->toHTMLSolved($form)), "id=" . $answerToUpdate[0]['id']);
         echo $question->toHTMLSolved($form);
         eF_deleteTableData("module_workbook_autosave", "item_id=" . $itemID . " AND users_LOGIN='******'login'] . "'");
         exit(0);
     } else {
         if ($currentUser->getRole($this->getCurrentLesson()) == 'professor' || $currentUser->getRole($this->getCurrentLesson()) == 'student') {
             $workbookItems = $this->getWorkbookItems($currentLessonID);
             $smarty->assign("T_WORKBOOK_ITEMS", $workbookItems);
             $smarty->assign("T_WORKBOOK_LESSONS", $workbookLessons);
             $isWorkbookPublished = $this->isWorkbookPublished($currentLessonID);
             $smarty->assign("T_WORKBOOK_IS_PUBLISHED", $isWorkbookPublished);
             $smarty->assign("T_WORKBOOK_NON_OPTIONAL_QUESTIONS_NR", $nonOptionalQuestionsNr);
         }
         if ($currentUser->getRole($this->getCurrentLesson()) == 'professor') {
             $workbookOptions[] = array('text' => _SETTINGS, 'image' => $this->moduleBaseLink . 'images/settings.png', 'href' => $this->moduleBaseUrl . '&edit_settings=1&popup=1', 'onClick' => "eF_js_showDivPopup(event, '" . _SETTINGS . "', 0)", 'target' => 'POPUP_FRAME', 'id' => 'edit_settings');
             $workbookOptions[] = array('text' => _WORKBOOK_POPUP_INFO, 'image' => $this->moduleBaseLink . 'images/info.png', 'href' => $this->moduleBaseUrl . '&popup_info=1&popup=1', 'onClick' => "eF_js_showDivPopup(event, '" . _WORKBOOK_POPUP_INFO . "', 2)", 'target' => 'POPUP_FRAME', 'id' => 'popup_info');
             $smarty->assign("T_WORKBOOK_OPTIONS", $workbookOptions);
         } else {
             if ($currentUser->getRole($this->getCurrentLesson()) == 'student') {
                 $workbookAnswers = $this->getWorkbookAnswers($currentUser->user['login'], array_keys($workbookItems));
                 $smarty->assign("T_WORKBOOK_ANSWERS", $workbookAnswers);
                 $autoSaveAnswers = $this->getAutoSaveAnswers($currentUser->user['login'], array_keys($workbookItems));
                 $smarty->assign("T_WORKBOOK_AUTOSAVE_ANSWERS", $autoSaveAnswers);
                 $studentProgress = $this->getStudentProgress($currentUser->user['login'], $currentLessonID);
                 $smarty->assign("T_WORKBOOK_STUDENT_PROGRESS", $studentProgress);
                 $isWorkbookCompleted = $this->isWorkbookCompleted($currentUser->user['login'], $currentLessonID, array_keys($workbookItems), $nonOptionalQuestionsNr);
                 $smarty->assign("T_WORKBOOK_IS_COMPLETED", $isWorkbookCompleted);
             }
         }
     }
     if ($currentUser->getRole($this->getCurrentLesson()) == 'professor') {
         return $this->moduleBaseDir . "module_workbook_professor.tpl";
     } else {
         if ($currentUser->getRole($this->getCurrentLesson()) == 'student') {
             return $this->moduleBaseDir . "module_workbook_student.tpl";
         }
     }
 }
コード例 #9
0
    $pearDB->query(sprintf($queryInsert, $pearDB->escape($values['centreon_nagvis_auth']), 'centreon_nagvis_auth'));
    $pearDB->query(sprintf($queryInsert, $pearDB->escape($values['centreon_nagvis_single_user']), 'centreon_nagvis_single_user'));
}
/*
 * Get options
 */
if (!isset($values)) {
    $values = array();
    $query = 'SELECT `key`, `value` FROM `options` WHERE `key` IN ("centreon_nagvis_uri", "centreon_nagvis_path", "centreon_nagvis_auth", "centreon_nagvis_single_user")';
    $res = $pearDB->query($query);
    if (!PEAR::isError($res)) {
        while ($row = $res->fetchRow()) {
            $values[$row['key']] = $row['value'];
        }
    }
}
$form->setDefaults($values);
/*
 *
 * Smarty template Init
 *
 */
$tpl = new Smarty();
$tpl = initSmartyTpl($path, $tpl);
$tpl->assign('p', $p);
$renderer = new HTML_QuickForm_Renderer_ArraySmarty($tpl, true);
$renderer->setRequiredTemplate('{$label}&nbsp;<font color="red" size="1">*</font>');
$renderer->setErrorTemplate('<font color="red">{$error}</font><br />{$html}');
$form->accept($renderer);
$tpl->assign('form', $renderer->toArray());
$tpl->display("nagvis-config.ihtml");
コード例 #10
0
ファイル: digests.php プロジェクト: kaseya-university/efront
 $config_form->addElement('submit', 'submit_variables', _SUBMIT, 'class = "flatButton"');
 $notification_configurations = array('notifications_use_cron', 'notifications_pageloads', 'notifications_maximum_inter_time', 'notifications_messages_per_time', 'notifications_max_sent_messages', 'notifications_send_mode');
 foreach ($notification_configurations as $conf_option) {
     $config_form->setDefaults(array($conf_option => $GLOBALS['configuration'][$conf_option]));
 }
 if ($config_form->isSubmitted()) {
     foreach ($notification_configurations as $conf_option) {
         EfrontConfiguration::setValue($conf_option, $config_form->exportValue($conf_option));
     }
     // Clear the stored sent messages according to the new limitations
     EfrontNotification::clearSentMessages();
     $message = _NOTIFICATIONCONFIGURATIONSUPDATEDSUCCESSFULLY;
     $message_type = 'success';
     eF_redirect("" . $_SESSION['s_type'] . ".php?ctg=digests&message=" . urlencode($message) . "&message_type=" . $message_type);
 }
 $renderer = new HTML_QuickForm_Renderer_ArraySmarty($smarty);
 //Create a smarty renderer
 $renderer->setRequiredTemplate('{$html}{if $required}
         &nbsp;<span class = "formRequired">*</span>
     {/if}');
 if (isset($currentUser->coreAccess['notifications']) && $currentUser->coreAccess['notifications'] != 'change') {
     $config_form->freeze();
 }
 $config_form->setJsWarnings(_BEFOREJAVASCRIPTERROR, _AFTERJAVASCRIPTERROR);
 //Set javascript error messages
 $config_form->setRequiredNote(_REQUIREDNOTE);
 $config_form->accept($renderer);
 //Assign this form to the renderer, so that corresponding template code is created
 $smarty->assign('T_NOTIFICATION_VARIABLES_FORM', $renderer->toArray());
 //Assign the form to the template
 $options = array(array('image' => '16x16/go_into.png', 'text' => _RESTOREDEFAULTNOTIFICATIONS, 'href' => 'administrator.php?ctg=digests&add_default=1'));
コード例 #11
0
ファイル: Renderer.php プロジェクト: hguru/224Civi
 /**
  * Creates an array representing an element containing
  * the key for storing this. We allow the parent to do most of the
  * work, but then we add some CiviCRM specific enhancements to
  * make the html compliant with our css etc
  *
  * @access private
  *
  * @param  object    An HTML_QuickForm_element object
  * @param  bool      Whether an element is required
  * @param  string    Error associated with the element
  *
  * @return array
  */
 function _elementToArray(&$element, $required, $error)
 {
     self::updateAttributes($element, $required, $error);
     $el = parent::_elementToArray($element, $required, $error);
     // add label html
     if (!empty($el['label'])) {
         $id = $element->getAttribute('id');
         if (!empty($id)) {
             $el['label'] = '<label for="' . $id . '">' . $el['label'] . '</label>';
         } else {
             $el['label'] = "<label>{$el['label']}</label>";
         }
     }
     return $el;
 }
コード例 #12
0
 public function getModule()
 {
     $smarty = $this->getSmartyVar();
     global $load_editor;
     $load_editor = true;
     $current_user = $this->getCurrentUser();
     $smarty->assign("T_MODULE_CURRENT_USER", $current_user->getType());
     $form = new HTML_QuickForm("module_mail_form", "post", $this->moduleBaseUrl, "", "id = 'module_mail_form'");
     $form->addElement('hidden', 'recipients', $_GET['rec']);
     $form->addElement('text', 'subject', _SUBJECT, 'class = "inputText" style = "width:400px"');
     $form->addElement('textarea', 'body', _BODY, 'class = "simpleEditor" style = "width:100%;height:200px"');
     $form->addElement('checkbox', 'email', _SENDASEMAILALSO, null, 'id = "send_as_email" class = "inputCheckBox"');
     $form->addRule('subject', _THEFIELD . ' "' . _SUBJECT . '" ' . _ISMANDATORY, 'required', null, 'client');
     $form->addRule('recipients', _THEFIELD . ' "' . _RECIPIENTS . '" ' . _ISMANDATORY, 'required', null, 'client');
     $form->addElement('file', 'attachment[0]', _ATTACHMENT, null, 'class = "inputText"');
     $form->addElement('submit', 'submit_mail', _SEND, 'class = "flatButton"');
     if ($form->isSubmitted() && $form->validate()) {
         $values = $form->exportValues();
         switch ($values['recipients']) {
             case "lesson_students":
                 $lesson = new EfrontLesson($_SESSION['s_lessons_ID']);
                 $lessonUsers = $lesson->getUsers("student");
                 foreach ($lessonUsers as $value) {
                     $mail_recipients[] = $value['login'];
                 }
                 //pr($mail_recipients);return;
                 break;
             case "lesson_professors":
                 $lesson = new EfrontLesson($_SESSION['s_lessons_ID']);
                 $lessonUsers = $lesson->getUsers("professor");
                 if (isset($_SESSION['s_courses_ID'])) {
                     $course = new EfrontCourse($_SESSION['s_courses_ID']);
                     $course_users = $course->getCourseUsers();
                     foreach ($lessonUsers as $key => $value) {
                         if (!isset($course_users[$key])) {
                             unset($lessonUsers[$key]);
                         }
                     }
                 }
                 foreach ($lessonUsers as $value) {
                     $mail_recipients[] = $value['login'];
                 }
                 break;
             case "admin":
                 $result = eF_getTableData("users", "*", "user_type='administrator' and user_types_ID=0 and archive = 0");
                 //not
                 foreach ($result as $value) {
                     $mail_recipients[] = $value['login'];
                 }
                 break;
         }
         //$list = implode(",",$mail_recipients);
         $pm = new eF_PersonalMessage($_SESSION['s_login'], $mail_recipients, $values['subject'], $values['body']);
         if ($_FILES['attachment']['name'][0] != "") {
             $maxFileSize = FileSystemTree::getUploadMaxSize();
             if ($_FILES['attachment']['size'][0] == 0 || $_FILES['attachment']['size'][0] > $maxFileSize * 1024) {
                 //	G_MAXFILESIZE is deprecated
                 $message = _EACHFILESIZEMUSTBESMALLERTHAN . " " . G_MAXFILESIZE . " Bytes";
                 $message_type = 'failure';
             }
             //Upload user avatar file
             $pm->sender_attachment_timestamp = time();
             $user_dir = G_UPLOADPATH . $_SESSION['s_login'] . '/message_attachments/Sent/' . $pm->sender_attachment_timestamp . '/';
             mkdir($user_dir, 0755);
             $filesystem = new FileSystemTree($user_dir);
             $uploadedFile = $filesystem->uploadFile('attachment', $user_dir, 0);
             $pm->sender_attachment_fileId = $uploadedFile['id'];
             $pm->setAttachment($uploadedFile['path']);
         }
         if ($pm->send($values['email'], $values)) {
             $message = _MESSAGEWASSENT;
             $message_type = 'success';
         } else {
             $message = $pm->errorMessage;
             $message_type = 'failure';
         }
     }
     $renderer = new HTML_QuickForm_Renderer_ArraySmarty($smarty);
     //Create a smarty renderer
     $renderer->setRequiredTemplate('{$html}{if $required}
     	&nbsp;<span class = "formRequired">*</span>
 		{/if}');
     $form->setJsWarnings(_BEFOREJAVASCRIPTERROR, _AFTERJAVASCRIPTERROR);
     //Set javascript error messages
     $form->setRequiredNote(_REQUIREDNOTE);
     $form->accept($renderer);
     //Assign this form to the renderer, so that corresponding template code is created
     $smarty->assign('T_MODULE_MAIL_FORM', $renderer->toArray());
     $smarty->assign("T_MESSAGE_MAIL", $message);
     $smarty->assign("T_MESSAGE_MAIL_TYPE", $message_type);
     //pr($renderer -> toArray());
     return true;
 }
コード例 #13
0
ファイル: Renderer.php プロジェクト: kcristiano/civicrm-core
 /**
  * Creates an array representing an element containing.
  * the key for storing this. We allow the parent to do most of the
  * work, but then we add some CiviCRM specific enhancements to
  * make the html compliant with our css etc
  *
  *
  * @param HTML_QuickForm_element $element
  * @param bool $required
  *   Whether an element is required.
  * @param string $error
  *   Error associated with the element.
  *
  * @return array
  */
 public function _elementToArray(&$element, $required, $error)
 {
     self::updateAttributes($element, $required, $error);
     $el = parent::_elementToArray($element, $required, $error);
     // add label html
     if (!empty($el['label'])) {
         $id = $element->getAttribute('id');
         if (!empty($id)) {
             $el['label'] = '<label for="' . $id . '">' . $el['label'] . '</label>';
         } else {
             $el['label'] = "<label>{$el['label']}</label>";
         }
     }
     // Display-only (frozen) elements
     if (!empty($el['frozen'])) {
         if ($element->getAttribute('data-api-entity') && $element->getAttribute('data-entity-value')) {
             $this->renderFrozenEntityRef($el, $element);
         } elseif ($element->getAttribute('type') == 'text' && $element->getAttribute('formatType')) {
             list($date, $time) = CRM_Utils_Date::setDateDefaults($element->getValue(), $element->getAttribute('formatType'), $element->getAttribute('format'), $element->getAttribute('timeformat'));
             $date .= $element->getAttribute('timeformat') ? " {$time}" : '';
             $el['html'] = $date . '<input type="hidden" value="' . $element->getValue() . '" name="' . $element->getAttribute('name') . '">';
         }
         // Render html for wysiwyg textareas
         if ($el['type'] == 'textarea' && isset($element->_attributes['class']) && strstr($element->_attributes['class'], 'wysiwyg')) {
             $el['html'] = '<span class="crm-frozen-field">' . $el['value'] . '</span>';
         } else {
             $el['html'] = '<span class="crm-frozen-field">' . $el['html'] . '</span>';
         }
     } else {
         if ($element->getType() == 'select' && $element->getAttribute('data-option-edit-path')) {
             $this->addOptionsEditLink($el, $element);
         }
         if ($element->getType() == 'group' && $element->getAttribute('allowClear')) {
             $this->appendUnselectButton($el, $element);
         }
     }
     return $el;
 }
コード例 #14
0
ファイル: Form.php プロジェクト: ryo88c/BEAR.Saturday
 /**
  * フォームレンダリング
  *
  * @param Smarty &$smarty  Smartyオブジェクト
  * @param string $ua       UAコード
  * @param bool   $enableJs JS有効?
  *
  * @return string
  */
 public static function renderForms(Smarty &$smarty, $ua, $enableJs = false)
 {
     static $result = false;
     static $done = false;
     if ($done === true) {
         return $result;
     }
     $removeJs = !$enableJs;
     $done = true;
     $result = array();
     foreach (self::$formNames as $formName) {
         $renderConfig = self::$_renderConfig[$formName];
         $adapter = isset($renderConfig['adapter']) ? $renderConfig['adapter'] : self::RENDERER_APP;
         $form = BEAR::get('BEAR_Form_' . $formName);
         $formErrors = false;
         $callback = isset($renderConfig['callback']) && is_callable($renderConfig['callback'], false) ? $renderConfig['callback'] : false;
         switch ($adapter) {
             case self::RENDERER_APP:
                 // DHTMLRulesTablelessレンダラ
                 // 単数フォーム(App_Form_Renderer_優先)
                 try {
                     $renderer = BEAR::dependency('App_Form_Renderer_' . $ua);
                 } catch (BEAR_Exception $e) {
                     $renderer = BEAR::dependency('BEAR_Form_Renderer_' . $ua);
                 } catch (Excption $e) {
                     throw $e;
                 }
                 assert(is_object($renderer));
                 if ($callback) {
                     call_user_func($callback, $renderer);
                 }
                 $form->accept($renderer);
                 // 完全なXHTML1.1に
                 $form->removeAttribute('name');
                 $formValue = $renderer->toHtml();
                 $formErrors = $form->_errors;
                 break;
             case self::RENDERER_DHTML_TABLELESS:
                 // DHTMLRulesTablelessレンダラ
                 // 単数フォーム
                 $renderer = new HTML_QuickForm_Renderer_Tableless($form);
                 // onblur有効
                 $form->getValidationScript();
                 $form->accept($renderer);
                 // 完全なXHTML1.1に
                 $form->removeAttribute('name');
                 if ($callback) {
                     call_user_func($callback, $renderer);
                 }
                 $formValue = $renderer->toHtml();
                 $formErrors = $form->_errors;
                 break;
             case self::RENDERER_SMARTY_ARRAY:
             default:
                 // HTML_QuickForm_Renderer_ArraySmartyレンダラ
                 // フォーム描画
                 $renderer = new HTML_QuickForm_Renderer_ArraySmarty($smarty);
                 $renderer->setRequiredTemplate(self::$requireTemplate);
                 $renderer->setErrorTemplate(self::$errorTemplate);
                 if ($callback) {
                     call_user_func($callback, $renderer);
                 }
                 $form->accept($renderer);
                 $formValue = $renderer->toArray();
                 break;
         }
         // エラーサマリー
         if (is_array($formErrors) && $formErrors && isset(self::$_renderConfig[$formName]['errors']) && self::$_renderConfig[$formName]['errors']) {
             $errorSummary = '<div class="form-errors"><ul><li>' . implode('</li><li>', $formErrors) . '</li></ul></div>';
             $smarty->assign(self::$_renderConfig[$formName]['errors'], $errorSummary);
         }
         // remove Javascript code if Docomo or AU
         if (is_array($formValue) && isset($formValue['javascript']) && $removeJs) {
             unset($formValue['javascript']);
         }
         $smarty->assign($formName, $formValue);
         $result[$formName] = $formValue;
     }
     return $result;
 }
コード例 #15
0
    public function getModule()
    {
        $smarty = $this->getSmartyVar();
        $currentLesson = $this->getCurrentLesson();
        $currentUser = $this->getCurrentUser();
        try {
            $role = $currentUser->getRole($this->getCurrentLesson());
        } catch (Exception $e) {
            $currentUser = EfrontUserFactory::factory($_SESSION['s_login']);
            $role = $currentUser->getRole($this->getCurrentLesson());
        }
        if (isset($_GET['delete_blog']) && eF_checkParameter($_GET['delete_blog'], 'id')) {
            $blog = eF_getTableData("module_blogs", "users_LOGIN", "id=" . $_GET['delete_blog']);
            if ($blog[0]['users_LOGIN'] != $_SESSION['s_login']) {
                eF_redirect("" . $this->moduleBaseUrl . "&message=" . urlencode(_BLOGS_NOACCESS));
                exit;
            }
            $articles = eF_getTableDataFlat("module_blogs_articles", "id", "blogs_ID=" . $_GET['delete_blog']);
            if (sizeof($articles) > 0) {
                $articlesList = implode(",", $articles['id']);
                eF_deleteTableData("module_blogs_comments", "blogs_articles_ID IN ({$articlesList})");
            }
            eF_deleteTableData("module_blogs_articles", "blogs_ID=" . $_GET['delete_blog']);
            eF_deleteTableData("module_blogs", "id=" . $_GET['delete_blog']);
        }
        if (isset($_GET['deactivate_blog']) && eF_checkParameter($_GET['deactivate_blog'], 'id')) {
            $blog = eF_getTableData("module_blogs", "users_LOGIN", "id=" . $_GET['deactivate_blog']);
            if ($blog[0]['users_LOGIN'] != $_SESSION['s_login']) {
                eF_redirect("" . $this->moduleBaseUrl . "&message=" . urlencode(_BLOGS_NOACCESS));
                exit;
            }
            if (eF_updateTableData("module_blogs", array('active' => 0), "id=" . $_GET['deactivate_blog'])) {
                $message = _BLOGS_BLOGDEACTIVATED;
                $message_type = 'success';
            } else {
                $message = _BLOGS_BLOGDEACTIVATEDPROBLEM;
                $message_type = "failure";
            }
        }
        if (isset($_GET['activate_blog']) && eF_checkParameter($_GET['activate_blog'], 'id')) {
            $blog = eF_getTableData("module_blogs", "users_LOGIN", "id=" . $_GET['activate_blog']);
            if ($blog[0]['users_LOGIN'] != $_SESSION['s_login']) {
                eF_redirect("" . $this->moduleBaseUrl . "&message=" . urlencode(_BLOGS_NOACCESS));
                exit;
            }
            if (eF_updateTableData("module_blogs", array('active' => 1), "id=" . $_GET['activate_blog'])) {
                $message = _BLOGS_BLOGACTIVATED;
                $message_type = 'success';
            } else {
                $message = _BLOGS_BLOGACTIVATEDPROBLEM;
                $message_type = "failure";
            }
        }
        if (isset($_GET['delete_article']) && eF_checkParameter($_GET['delete_article'], 'id')) {
            $blog = eF_getTableData("module_blogs_articles", "blogs_ID,users_LOGIN", "id=" . $_GET['delete_article']);
            $blogTemp = eF_getTableData("module_blogs", "users_LOGIN", "id=" . $blog[0]['blogs_ID']);
            if ($blog[0]['users_LOGIN'] != $_SESSION['s_login'] && $blogTemp[0]['users_LOGIN'] != $_SESSION['s_login']) {
                eF_redirect("" . $this->moduleBaseUrl . "&view_blog=" . $blog[0]['blogs_ID'] . "&message=" . urlencode(_BLOGS_NOACCESS));
                exit;
            }
            eF_deleteTableData("module_blogs_comments", "blogs_articles_ID=" . $_GET['delete_article']);
            eF_deleteTableData("module_blogs_articles", "id=" . $_GET['delete_article']);
            $message = _BLOGS_ARTICLEWASDELETEDSUCCESSFULLY;
            $message_type = "success";
            eF_redirect("" . $this->moduleBaseUrl . "&view_blog=" . $blog[0]['blogs_ID'] . "&message=" . urlencode($message) . "&message_type=" . $message_type);
        }
        if (isset($_GET['delete_comment']) && eF_checkParameter($_GET['delete_comment'], 'id')) {
            $article = eF_getTableData("module_blogs_articles", "blogs_ID,users_LOGIN", "id=" . $_GET['article_id']);
            $blogTemp = eF_getTableData("module_blogs", "users_LOGIN", "id=" . $article[0]['blogs_ID']);
            $commentTemp = eF_getTableData("module_blogs_comments", "users_LOGIN", "id=" . $_GET['delete_comment']);
            if ($commentTemp[0]['users_LOGIN'] != $_SESSION['s_login'] && $blogTemp[0]['users_LOGIN'] != $_SESSION['s_login']) {
                eF_redirect("" . $this->moduleBaseUrl . "&view_article=" . $_GET['article_id'] . "&message=" . urlencode(_BLOGS_NOACCESS));
                exit;
            }
            eF_deleteTableData("module_blogs_comments", "id=" . $_GET['delete_comment']);
            $message = _BLOGS_COMMENTWASDELETEDSUCCESSFULLY;
            $message_type = "success";
            eF_redirect("" . $this->moduleBaseUrl . "&view_article=" . $_GET['article_id'] . "&message=" . urlencode($message) . "&message_type=" . $message_type);
        }
        if (isset($_GET['add_blog']) || isset($_GET['edit_blog'])) {
            if (isset($_GET['add_blog']) && $_SESSION['s_type'] != "professor") {
                eF_redirect("" . $this->moduleBaseUrl . "&message=" . urlencode(_BLOGS_NOACCESS));
            }
            if (isset($_GET['edit_blog'])) {
                $blog_data = eF_getTableData("module_blogs", "*", "id=" . $_GET['edit_blog']);
                if ($blog_data[0]['users_LOGIN'] != $_SESSION['s_login']) {
                    eF_redirect("" . $this->moduleBaseUrl . "&message=" . urlencode(_BLOGS_NOACCESS));
                }
                $post_target = $this->moduleBaseUrl . '&edit_blog=' . $_GET['edit_blog'];
            } else {
                $post_target = $this->moduleBaseUrl . '&add_blog';
            }
            global $load_editor;
            $load_editor = true;
            $form = new HTML_QuickForm("blog_add_form", "post", $post_target . "&blog_id=" . $_GET['blog_id'], "", null, true);
            //Build the form
            $form->addElement('text', 'title', _TITLE, 'class = "inputText"');
            $form->addRule('title', _THEFIELD . ' "' . _TITLE . '" ' . _ISMANDATORY, 'required', null, 'client');
            $form->addElement('textarea', 'description', _DESCRIPTION, 'class = "inputContentTextarea simpleEditor" style = "width:100%;height:20em;"');
            $form->addElement("advcheckbox", "registered", _BLOGS_ACCESSIBLE, null, 'class = "inputCheckBox"', array(0, 1));
            $form->addElement('submit', 'submit_add_blog', _SUBMIT, 'class = "flatButton"');
            if (isset($_GET['edit_blog'])) {
                $form->setDefaults(array('title' => $blog_data[0]['name'], 'description' => $blog_data[0]['description'], 'registered' => $blog_data[0]['registered']));
            }
            if ($form->isSubmitted() && $form->validate()) {
                //If the form is submitted and validated
                $values = $form->exportValues();
                $fields = array("name" => $values['title'], "lessons_ID" => $values['lessons_ID'] ? $values['lessons_ID'] : $_SESSION['s_lessons_ID'], "description" => $values['description'], "registered" => $values['registered']);
                if (isset($_GET['edit_blog'])) {
                    if (eF_updateTableData("module_blogs", $fields, "id=" . $_GET['edit_blog'])) {
                        $message = _BLOGS_BLOGUPDATEDSUCCESSFULLY;
                        $message_type = 'success';
                    } else {
                        $message = _BLOGS_BLOGNOTUPDATED;
                        $message_type = 'failure';
                    }
                    eF_redirect("" . $this->moduleBaseUrl . "&message=" . urlencode($message) . "&message_type=" . $message_type);
                } else {
                    $fields['users_LOGIN'] = $_SESSION['s_login'];
                    $fields['timestamp'] = time();
                    //pr($fields);
                    $new_id = eF_insertTableData("module_blogs", $fields);
                    if ($new_id) {
                        $message = _BLOGS_BLOGADDEDSUCCESSFULLY;
                        $message_type = 'success';
                        eF_redirect("" . $this->moduleBaseUrl . "&message=" . urlencode($message) . "&message_type=" . $message_type . "&edit_blog=" . $new_id . "&tab=blog_creators");
                    } else {
                        $message = _BLOGS_BLOGNOTADDED;
                        $message_type = 'failure';
                        eF_redirect("" . $this->moduleBaseUrl . "&message=" . urlencode($message) . "&message_type=" . $message_type);
                    }
                }
            }
            $renderer = new HTML_QuickForm_Renderer_ArraySmarty($smarty);
            //Create a smarty renderer
            $renderer->setRequiredTemplate('{$html}{if $required}
				&nbsp;<span class = "formRequired">*</span>
			{/if}');
            $form->setJsWarnings(_BEFOREJAVASCRIPTERROR, _AFTERJAVASCRIPTERROR);
            //Set javascript error messages
            $form->setRequiredNote(_REQUIREDNOTE);
            $form->accept($renderer);
            //Assign this form to the renderer, so that corresponding template code is created
            $smarty->assign('T_BLOG_ADD_FORM', $renderer->toArray());
            //Assign the form to the template
            try {
                $lessonUsers = $currentLesson->getUsers();
                //Get all users that have this lesson
                unset($lessonUsers[$currentUser->login]);
                //Remove the current user from the list, he can't set parameters for his self!
                $users = $lessonUsers;
                $blogsCreators = eF_getTableDataFlat("module_blogs_users", "*", "blogs_ID=" . $_GET['edit_blog']);
                $creatorsAssoc = array_combine(array_values($blogsCreators['users_LOGIN']), array_values($blogsCreators['users_LOGIN']));
                $nonBlogsCreators = array_diff_key($users, $creatorsAssoc);
                $blogsCreatorsTemp = array_diff_key($users, $nonBlogsCreators);
                foreach ($users as $key => $user) {
                    in_array($key, array_values($blogsCreators['users_LOGIN'])) ? $users[$key]['blog_creator'] = true : ($users[$key]['blog_creator'] = false);
                }
                //pr($users);
                $roles = eF_getTableDataFlat("user_types", "name", "active=1 AND basic_user_type!='administrator'");
                //Get available roles
                if (sizeof($roles) > 0) {
                    $roles = array_combine($roles['name'], $roles['name']);
                    //Match keys with values, it's more practical this way
                }
                $roles = array_merge(array('student' => _STUDENT, 'professor' => _PROFESSOR), $roles);
                //Append basic user types to the beginning of the array
                //pr($roles);
                if (isset($_GET['ajax']) && $_GET['ajax'] == 'usersTable') {
                    isset($_GET['limit']) && eF_checkParameter($_GET['limit'], 'uint') ? $limit = $_GET['limit'] : ($limit = G_DEFAULT_TABLE_SIZE);
                    if (isset($_GET['sort']) && eF_checkParameter($_GET['sort'], 'text')) {
                        $sort = $_GET['sort'];
                        isset($_GET['order']) && $_GET['order'] == 'desc' ? $order = 'desc' : ($order = 'asc');
                    } else {
                        $sort = 'login';
                    }
                    $users = eF_multiSort($users, $sort, $order);
                    $smarty->assign("T_USERS_SIZE", sizeof($users));
                    if (isset($_GET['filter'])) {
                        $users = eF_filterData($users, $_GET['filter']);
                    }
                    if (isset($_GET['limit']) && eF_checkParameter($_GET['limit'], 'int')) {
                        isset($_GET['offset']) && eF_checkParameter($_GET['offset'], 'int') ? $offset = $_GET['offset'] : ($offset = 0);
                        $users = array_slice($users, $offset, $limit);
                    }
                    $smarty->assign("T_ROLES", $roles);
                    $smarty->assign("T_ALL_USERS", $users);
                    $smarty->assign("T_BLOGS_USERS", $blogsCreators['users_LOGIN']);
                    //We assign separately the lesson's users, to know when to display the checkboxes as "checked"
                    $smarty->assign("T_CURRENT_USER", $currentUser);
                    return true;
                }
            } catch (Exception $e) {
                $smarty->assign("T_EXCEPTION_TRACE", $e->getTraceAsString());
                $message = $e->getMessage() . ' (' . $e->getCode() . ') &nbsp;<a href = "javascript:void(0)" onclick = "eF_js_showDivPopup(event, \'' . _ERRORDETAILS . '\', 2, \'error_details\')">' . _MOREINFO . '</a>';
                $message_type = 'failure';
            }
            if (isset($_GET['postAjaxRequest'])) {
                try {
                    if (isset($_GET['login']) && eF_checkParameter($_GET['login'], 'login')) {
                        if (!in_array($_GET['login'], array_values($blogsCreators['users_LOGIN']))) {
                            $fields = array('blogs_ID' => $_GET['edit_blog'], 'users_login' => $_GET['login']);
                            $res = eF_insertTableData("module_blogs_users", $fields);
                        }
                        if (in_array($_GET['login'], array_values($blogsCreators['users_LOGIN']))) {
                            eF_deleteTableData("module_blogs_users", "blogs_ID=" . $_GET['edit_blog'] . " AND users_LOGIN='******'login'] . "'");
                        }
                    } else {
                        if (isset($_GET['addAll'])) {
                            isset($_GET['filter']) ? $nonBlogsCreators = eF_filterData($nonBlogsCreators, $_GET['filter']) : null;
                            foreach ($nonBlogsCreators as $key => $value) {
                                $fields = array('blogs_ID' => $_GET['edit_blog'], 'users_login' => $key);
                                $res = eF_insertTableData("module_blogs_users", $fields);
                            }
                        } else {
                            if (isset($_GET['removeAll'])) {
                                isset($_GET['filter']) ? $blogCreators = eF_filterData($blogsCreatorsTemp, $_GET['filter']) : null;
                                foreach ($blogsCreatorsTemp as $key => $value) {
                                    eF_deleteTableData("module_blogs_users", "blogs_ID=" . $_GET['edit_blog'] . " AND users_LOGIN='******'");
                                }
                            }
                        }
                    }
                } catch (Exception $e) {
                    header("HTTP/1.0 500 ");
                    echo $e->getMessage() . ' (' . $e->getCode() . ')';
                }
                exit;
            }
        } elseif (isset($_GET['add_article']) || isset($_GET['edit_article'])) {
            $resAccess = eF_getTableData("module_blogs", "*", "id=" . $_GET['blog_id']);
            if (isset($_GET['edit_article'])) {
                $article_data = eF_getTableData("module_blogs_articles", "*", "id=" . $_GET['edit_article']);
                if ($resAccess[0]['users_LOGIN'] != $_SESSION['s_login'] && $article_data[0]['users_LOGIN'] != $_SESSION['s_login']) {
                    eF_redirect("" . $this->moduleBaseUrl . "&view_blog=" . $_GET['blog_id'] . "&message=" . urlencode(_BLOGS_NOACCESS));
                }
                $post_target = $this->moduleBaseUrl . '&edit_article=' . $_GET['edit_article'];
            } else {
                $creator = eF_getTableData("module_blogs_users", "*", "blogs_ID=" . $_GET['blog_id'] . " and users_LOGIN='******'s_login'] . "'");
                if ($resAccess[0]['users_LOGIN'] != $_SESSION['s_login'] && sizeof($creator) == 0) {
                    eF_redirect("" . $this->moduleBaseUrl . "&view_blog=" . $_GET['blog_id'] . "&message=" . urlencode(_BLOGS_NOACCESS));
                }
                $post_target = $this->moduleBaseUrl . '&add_article';
            }
            global $load_editor;
            $load_editor = true;
            $form = new HTML_QuickForm("article_add_form", "post", $post_target . "&blog_id=" . $_GET['blog_id'], "", null, true);
            //Build the form
            $form->addElement('text', 'title', _TITLE, 'class = "inputText"');
            $form->addRule('title', _THEFIELD . ' "' . _TITLE . '" ' . _ISMANDATORY, 'required', null, 'client');
            $form->addElement('textarea', 'data', _DATA, 'class = "simpleEditor"  id="blog_article_data" style = "width:100%;height:25em;"');
            $form->addElement('submit', 'submit_add_article', _SUBMIT, 'class = "flatButton"');
            if (isset($_GET['edit_article'])) {
                $form->setDefaults(array('title' => $article_data[0]['title'], 'data' => $article_data[0]['data']));
            }
            if ($form->isSubmitted() && $form->validate()) {
                //If the form is submitted and validated
                $values = $form->exportValues();
                $fields = array("title" => $values['title'], "data" => $values['data']);
                if (isset($_GET['edit_article'])) {
                    if (eF_updateTableData("module_blogs_articles", $fields, "id=" . $_GET['edit_article'])) {
                        $message = _BLOGS_ARTICLEUPDATEDSUCCESSFULLY;
                        $message_type = 'success';
                    } else {
                        $message = _BLOGS_ARTICLENOTUPDATED;
                        $message_type = 'failure';
                    }
                    eF_redirect("" . $this->moduleBaseUrl . "&view_blog=" . $_GET['blog_id'] . "&message=" . urlencode($message) . "&message_type=" . $message_type);
                } else {
                    $fields['users_LOGIN'] = $_SESSION['s_login'];
                    $fields['timestamp'] = time();
                    $fields['blogs_ID'] = $_GET['blog_id'];
                    //pr($fields);exit;
                    $new_id = eF_insertTableData("module_blogs_articles", $fields);
                    if ($new_id) {
                        $message = _BLOGS_ARTICLEADDEDSUCCESSFULLY;
                        $message_type = 'success';
                    } else {
                        $message = _BLOGS_ARTICLENOTADDED;
                        $message_type = 'failure';
                    }
                    eF_redirect("" . $this->moduleBaseUrl . "&view_blog=" . $_GET['blog_id'] . "&message=" . urlencode($message) . "&message_type=" . $message_type);
                }
            }
            $renderer = new HTML_QuickForm_Renderer_ArraySmarty($smarty);
            //Create a smarty renderer
            $renderer->setRequiredTemplate('{$html}{if $required}
				&nbsp;<span class = "formRequired">*</span>
			{/if}');
            $form->setJsWarnings(_BEFOREJAVASCRIPTERROR, _AFTERJAVASCRIPTERROR);
            //Set javascript error messages
            $form->setRequiredNote(_REQUIREDNOTE);
            $form->accept($renderer);
            //Assign this form to the renderer, so that corresponding template code is created
            $smarty->assign('T_ARTICLE_ADD_FORM', $renderer->toArray());
            //Assign the form to the template
        } elseif (isset($_GET['add_comment']) || isset($_GET['edit_comment'])) {
            if (isset($_GET['edit_comment'])) {
                $comment_data = eF_getTableData("module_blogs_comments", "*", "id=" . $_GET['edit_comment']);
                $blogAccess = eF_getTableData("module_blogs_articles", "*", "id=" . $_GET['article_id']);
                if ($comment_data[0]['users_LOGIN'] != $_SESSION['s_login'] && $blogAccess[0]['users_LOGIN'] != $_SESSION['s_login']) {
                    eF_redirect("" . $this->moduleBaseUrl . "&view_article=" . $_GET['article_id'] . "&message=" . urlencode(_BLOGS_NOACCESS));
                }
                $post_target = $this->moduleBaseUrl . '&edit_comment=' . $_GET['edit_comment'];
            } else {
                $post_target = $this->moduleBaseUrl . '&add_comment';
            }
            global $load_editor;
            $load_editor = true;
            $form = new HTML_QuickForm("blog_comment_form", "post", $post_target . "&article_id=" . $_GET['article_id'], "", null, true);
            //Build the form
            $form->addElement('textarea', 'data', _COMMENT, 'class = "inputContentTextarea simpleEditor" style = "width:80%;height:10em;"');
            $form->addElement('submit', 'submit_add_comment', _SUBMIT, 'class = "flatButton"');
            if (isset($_GET['edit_comment'])) {
                $form->setDefaults(array('data' => $comment_data[0]['data']));
            }
            if ($form->isSubmitted() && $form->validate()) {
                //If the form is submitted and validated
                $values = $form->exportValues();
                $fields = array("data" => $values['data'], "users_LOGIN" => $currentUser->user['login'], "blogs_articles_ID" => $_GET['article_id'], "timestamp" => time());
                if (isset($_GET['edit_comment'])) {
                    if (eF_updateTableData("module_blogs_comments", $fields, "id=" . $_GET['edit_comment'])) {
                        $message = _BLOGS_COMMENTUPDATEDSUCCESSFULLY;
                        $message_type = 'success';
                    } else {
                        $message = _BLOGS_COMMENTNOTUPDATED;
                        $message_type = 'failure';
                    }
                    eF_redirect("" . $this->moduleBaseUrl . "&view_article=" . $_GET['article_id'] . "&message=" . urlencode($message) . "&message_type=" . $message_type);
                } else {
                    //pr($fields);
                    $new_id = eF_insertTableData("module_blogs_comments", $fields);
                    if ($new_id) {
                        $message = _BLOGS_COMMENTADDEDSUCCESSFULLY;
                        $message_type = 'success';
                    } else {
                        $message = _BLOGS_COMMENTNOTADDED;
                        $message_type = 'failure';
                    }
                    eF_redirect("" . $this->moduleBaseUrl . "&view_article=" . $_GET['article_id'] . "&message=" . urlencode($message) . "&message_type=" . $message_type);
                }
            }
            $renderer = new HTML_QuickForm_Renderer_ArraySmarty($smarty);
            //Create a smarty renderer
            $renderer->setRequiredTemplate('{$html}{if $required}
				&nbsp;<span class = "formRequired">*</span>
			{/if}');
            $form->setJsWarnings(_BEFOREJAVASCRIPTERROR, _AFTERJAVASCRIPTERROR);
            //Set javascript error messages
            $form->setRequiredNote(_REQUIREDNOTE);
            $form->accept($renderer);
            //Assign this form to the renderer, so that corresponding template code is created
            $smarty->assign('T_COMMENT_ADD_FORM', $renderer->toArray());
            //Assign the form to the template
            $article = eF_getTableData("module_blogs_articles", "*", "id=" . $_GET['article_id']);
            $blogComments = eF_getTableData("module_blogs_comments", "*", "blogs_articles_ID=" . $_GET['article_id'], "timestamp asc");
            $article[0]['comments'] = sizeof($blogComments);
            $blog = eF_getTableData("module_blogs", "*", "id=" . $article[0]['blogs_ID']);
            $creator = eF_getTableData("module_blogs_users", "*", "blogs_ID=" . $article[0]['blogs_ID'] . " and users_LOGIN='******'s_login'] . "'");
            if (sizeof($creator) > 0) {
                $smarty->assign("T_BLOGS_ISBLOGCREATOR", 1);
            }
            $smarty->assign("T_BLOGS_BLOG", $blog[0]);
            $smarty->assign("T_BLOGS_ARTICLE", $article[0]);
            $smarty->assign("T_BLOGS_COMMENTS", $blogComments);
        } elseif (isset($_GET['view_blog'])) {
            $blog = eF_getTableData("module_blogs", "*", "id=" . $_GET['view_blog']);
            $creator = eF_getTableData("module_blogs_users", "*", "blogs_ID=" . $_GET['view_blog'] . " and users_LOGIN='******'s_login'] . "'");
            if (sizeof($creator) > 0) {
                $smarty->assign("T_BLOGS_ISBLOGCREATOR", 1);
            }
            $blogPosts = eF_getTableData("module_blogs_articles", "*", "blogs_ID=" . $_GET['view_blog'], "timestamp desc");
            //pr($blogPosts);
            $indexing = array();
            foreach ($blogPosts as $key => $value) {
                $indexing[date('Y', $blogPosts[$key]['timestamp'])][date('F', $blogPosts[$key]['timestamp'])][$value['id']] = $value['title'];
                $blogComments = eF_getTableData("module_blogs_comments", "*", "blogs_articles_ID=" . $value['id'], "timestamp desc");
                $blogPosts[$key]['last_comment'] = $blogComments[0];
                $blogPosts[$key]['comments'] = sizeof($blogComments);
            }
            //pr($indexing);
            //pr($blogPosts);
            $lastComments = eF_getTableData("module_blogs_comments as com,module_blogs_articles as art", "com.id as comment_id,com.data,com.timestamp,art.id as article_id,art.title,com.users_LOGIN", "com.blogs_articles_ID=art.id and art.blogs_ID=" . $_GET['view_blog'], "com.timestamp desc");
            $smarty->assign("T_BLOGS_INDEXING", $indexing);
            $smarty->assign("T_BLOGS_LASTCOMMENTS", $lastComments);
            $smarty->assign("T_BLOGS_BLOG", $blog[0]);
            $smarty->assign("T_BLOGS_POSTS", $blogPosts);
        } elseif (isset($_GET['view_article'])) {
            $article = eF_getTableData("module_blogs_articles", "*", "id=" . $_GET['view_article']);
            $blogComments = eF_getTableData("module_blogs_comments", "*", "blogs_articles_ID=" . $_GET['view_article'], "timestamp asc");
            $article[0]['comments'] = sizeof($blogComments);
            $blog = eF_getTableData("module_blogs", "*", "id=" . $article[0]['blogs_ID']);
            $creator = eF_getTableData("module_blogs_users", "*", "blogs_ID=" . $article[0]['blogs_ID'] . " and users_LOGIN='******'s_login'] . "'");
            if (sizeof($creator) > 0) {
                $smarty->assign("T_BLOGS_ISBLOGCREATOR", 1);
            }
            $smarty->assign("T_BLOGS_BLOG", $blog[0]);
            $smarty->assign("T_BLOGS_ARTICLE", $article[0]);
            $smarty->assign("T_BLOGS_COMMENTS", $blogComments);
        } else {
            $lessonBlogs = eF_getTableData("module_blogs", "*", "lessons_ID=" . $currentLesson->lesson['id']);
            foreach ($lessonBlogs as $key => $value) {
                //echo $value['id'];
                $res = eF_getTableData("module_blogs_articles", "*", "blogs_ID=" . $value['id'], "timestamp desc");
                $lessonBlogs[$key]['last_article'] = $res[0];
                /*		$creators  = eF_getTableData("module_blogs_users","*","blogs_ID=".$value['id']." and users_LOGIN='******'s_login']."'");
                				if (sizeof($creators) > 0) {
                					$lessonBlogs[$key]['is_creator'] = 1;
                				} else{
                					$lessonBlogs[$key]['is_creator'] = 0;
                				} */
            }
            //pr($lessonBlogs);
            //$smarty -> assign("T_BLOGS_LASTARTICLE", $lastArticle);
            $smarty->assign("T_BLOGS_LESSONBLOGS", $lessonBlogs);
            $smarty->assign("T_BLOGS_CLESSON", $currentLesson);
            $smarty->assign("T_BLOGS_CUSER", $currentUser);
            $smarty->assign("T_BLOGS_ROLE", $role);
            return true;
        }
    }