public function execute() { $tp = SJB_System::getTemplateProcessor(); $action = SJB_Request::getVar('action', 'list'); $sid = SJB_Request::getVar('sid', null, null, 'int'); if (SJB_Acl::getInstance()->isAllowed('use_screening_questionnaires')) { switch ($action) { case 'delete': if (SJB_ScreeningQuestionnaires::isUserOwnerQuestionnaire(SJB_UserManager::getCurrentUserSID(), $sid)) { SJB_ScreeningQuestionnaires::deleteQuestionnaireBySID($sid); } $action = 'list'; break; } $tp->assign('questionnaires', SJB_ScreeningQuestionnaires::getList(SJB_UserManager::getCurrentUserSID())); $tp->assign('action', $action); $tp->display('screening_questionnaires.tpl'); } }
public function execute() { $tp = SJB_System::getTemplateProcessor(); $sid = SJB_Request::getVar('sid', null, null, 'int'); if (isset($_REQUEST['passed_parameters_via_uri'])) { $passed_parameters_via_uri = SJB_UrlParamProvider::getParams(); $sid = isset($passed_parameters_via_uri[0]) ? $passed_parameters_via_uri[0] : null; } $request['field_sid'] = $sid; $display_list_controller = new SJB_ScreeningQuestionnairesDisplayListController($request); $questionInfo = SJB_ScreeningQuestionnairesFieldManager::getFieldInfoBySID($sid); if (!empty($questionInfo['questionnaire_sid']) && SJB_ScreeningQuestionnaires::isUserOwnerQuestionnaire(SJB_UserManager::getCurrentUserSID(), $questionInfo['questionnaire_sid'])) { $questionInfo = array_merge($questionInfo, $_REQUEST); $questionnaire_field = new SJB_ScreeningQuestionnairesField($questionInfo); $questionnaire_field->deleteProperty('maxlength'); $questionnaire_field->deleteProperty('template'); $add_questionnaire_field_form = new SJB_Form($questionnaire_field); $add_questionnaire_field_form->registerTags($tp); $form_is_submitted = SJB_Request::getVar('action', '') == 'add'; $errors = null; $type = SJB_Request::getVar('type', false); $savedType = $display_list_controller->field->getProperty('type')->value; $type = $type ? $type : $savedType; $answers = SJB_Request::getVar('answer', false); $score = SJB_Request::getVar('score', false); $answer_boolean = SJB_Request::getVar('answer_boolean', false); $score_boolean = SJB_Request::getVar('score_boolean', false); if ($type != 'string') { $answers = $answers ? $answers : $display_list_controller->list_items['answer']; $score = $score ? $score : $display_list_controller->list_items['score']; $answer_boolean = $answer_boolean ? $answer_boolean : $display_list_controller->list_items['answer']; $score_boolean = $score_boolean ? $score_boolean : $display_list_controller->list_items['score']; } if ($answer_boolean && $score_boolean) { foreach ($answer_boolean as $key => $val) { $score_boolean[strtolower($val)] = $score_boolean[$key]; } } if ($form_is_submitted && $add_questionnaire_field_form->isDataValid($errors)) { $questionnaire_field->addProperty(array('id' => 'questionnaire_sid', 'type' => 'id', 'value' => $questionInfo['questionnaire_sid'], 'is_system' => true)); $id = $questionnaire_field->getProperty('caption'); $questionnaire_field->addProperty(array('id' => 'id', 'type' => 'string', 'value' => md5($id->value), 'is_system' => true)); $questionnaire_field->setSID($sid); $questionnairesListItemManager = new SJB_ScreeningQuestionnairesListItemManager(); $questionnairesListItemManager->deleteItemsByFieldSID($sid); SJB_ScreeningQuestionnairesFieldManager::saveQuestion($questionnaire_field); if ($type == 'boolean') { $request['list_multiItem_value'] = $answer_boolean; $request['field_sid'] = $questionnaire_field->sid; $request['score'] = $score_boolean; $edit_list_controller = new SJB_ScreeningQuestionnairesListController($request); if ($edit_list_controller->isvalidFieldSID()) { $edit_list_controller->saveItem(true); } } elseif ($type != 'string') { $request['list_multiItem_value'] = $answers; $request['field_sid'] = $questionnaire_field->sid; $request['score'] = $score; $edit_list_controller = new SJB_ScreeningQuestionnairesListController($request); if ($edit_list_controller->isvalidFieldSID()) { $edit_list_controller->saveItem(true); } } $questionnaire_sid = $questionnaire_field->getSID(); SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . "/edit-questions/{$questionInfo['questionnaire_sid']}/?edit=1"); } else { switch ($type) { case 'boolean': $tp->assign('answer_boolean', $answer_boolean); $tp->assign('score_boolean', $score_boolean); break; case 'multilist': case 'list': $tp->assign('answers', $answers); $tp->assign('score', $score); break; } $tp->assign('errors', $errors); $tp->assign('action', 'edit'); $tp->assign('questionnaire_sid', $questionInfo['questionnaire_sid']); $add_questionnaire_field_form->registerTags($tp); $tp->assign('form_fields', $add_questionnaire_field_form->getFormFieldsInfo()); $tp->display('add_questions.tpl'); } } }
public function execute() { $tp = SJB_System::getTemplateProcessor(); $action = SJB_Request::getVar('action', false); $sid = SJB_Request::getVar('sid', null, null, 'int'); $edit = SJB_Request::getVar('edit', false); if (isset($_REQUEST['passed_parameters_via_uri'])) { $passed_parameters_via_uri = SJB_UrlParamProvider::getParams(); $sid = isset($passed_parameters_via_uri[0]) ? $passed_parameters_via_uri[0] : null; $questionSID = isset($passed_parameters_via_uri[1]) ? $passed_parameters_via_uri[1] : false; } if (SJB_ScreeningQuestionnaires::isUserOwnerQuestionnaire(SJB_UserManager::getCurrentUserSID(), $sid)) { switch ($action) { case 'delete': if ($questionSID) { SJB_ScreeningQuestionnairesFieldManager::deleteQuestionBySID($questionSID); } SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . "/edit-questions/{$sid}/"); break; case 'move_up': $questionSID = SJB_Request::getVar('question', false); if ($questionSID) { SJB_ScreeningQuestionnairesFieldManager::moveUpFieldBySID($questionSID); } break; case 'move_down': $questionSID = SJB_Request::getVar('question', false); if ($questionSID) { SJB_ScreeningQuestionnairesFieldManager::moveDownFieldBySID($questionSID); } break; } $questionnaire_field = new SJB_ScreeningQuestionnairesField($_REQUEST); $questions = array(); if ($sid) { $questions = SJB_ScreeningQuestionnairesFieldManager::getFieldsInfoByQuestionnairesSID($sid); $tp->assign('questionnarieInfo', SJB_ScreeningQuestionnaires::getInfoBySID($sid)); } $add_questionnaire_field_form = new SJB_Form($questionnaire_field); $add_questionnaire_field_form->registerTags($tp); $form_is_submitted = SJB_Request::getVar('action', '') == 'add'; $errors = null; $answers = SJB_Request::getVar('answer', false); $score = SJB_Request::getVar('score', false); $answer_boolean = SJB_Request::getVar('answer_boolean', false); $score_boolean = SJB_Request::getVar('score_boolean', false); $type = SJB_Request::getVar('type', false); if (is_array($answers)) { foreach ($answers as $key => $val) { if ($key != 0 && $val == null) { unset($answers[$key]); } } } if ($form_is_submitted && $add_questionnaire_field_form->isDataValid($errors)) { $questionnaire_field->addProperty(array('id' => 'questionnaire_sid', 'type' => 'id', 'value' => $sid, 'is_system' => true)); $id = $questionnaire_field->getProperty('caption'); $questionnaire_field->addProperty(array('id' => 'id', 'type' => 'string', 'value' => md5($id->value), 'is_system' => true)); SJB_ScreeningQuestionnairesFieldManager::saveQuestion($questionnaire_field); if ($type == 'boolean') { $request['list_multiItem_value'] = $answer_boolean; $request['field_sid'] = $questionnaire_field->sid; $request['score'] = $score_boolean; $edit_list_controller = new SJB_ScreeningQuestionnairesListController($request); if ($edit_list_controller->isvalidFieldSID()) { $edit_list_controller->saveItem(true); } } elseif ($type != 'string') { $request['list_multiItem_value'] = $answers; $request['field_sid'] = $questionnaire_field->sid; $request['score'] = $score; $edit_list_controller = new SJB_ScreeningQuestionnairesListController($request); if ($edit_list_controller->isvalidFieldSID()) { $edit_list_controller->saveItem(true); } } $questionnaire_sid = $questionnaire_field->getSID(); SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . "/edit-questions/{$sid}/"); } else { switch ($type) { case 'boolean': $tp->assign('answer_boolean', $answer_boolean); $tp->assign('score_boolean', $score_boolean); break; case 'multilist': case 'list': $tp->assign('answers', $answers); $tp->assign('score', $score); break; } $tp->assign('edit', $edit); $tp->assign('sid', $sid); $tp->assign('questions', $questions); $tp->assign('action', 'edit'); $tp->assign('errors', $errors); $add_questionnaire_field_form->registerTags($tp); $tp->assign('form_fields', $add_questionnaire_field_form->getFormFieldsInfo()); $tp->display('edit_questions.tpl'); } } }
public function execute() { $tp = SJB_System::getTemplateProcessor(); $action = SJB_Request::getVar('action', 'add'); $submit = SJB_Request::getVar('submit', false); $template = SJB_Request::getVar('template_name', 'add_questionnaire.tpl'); $sid = SJB_Request::getVar('sid', null, null, 'int'); $edit = SJB_Request::getVar('edit', false); if (isset($_REQUEST['passed_parameters_via_uri'])) { $passed_parameters_via_uri = SJB_UrlParamProvider::getParams(); $sid = isset($passed_parameters_via_uri[0]) ? $passed_parameters_via_uri[0] : null; } $errors = array(); $questionnaireInfo = SJB_ScreeningQuestionnaires::getInfoBySID($sid); if (!empty($questionnaireInfo['sid']) && !SJB_ScreeningQuestionnaires::isUserOwnerQuestionnaire(SJB_UserManager::getCurrentUserSID(), $questionnaireInfo['sid'])) { SJB_FlashMessages::getInstance()->addError('NOT_OWNER'); } else { if (SJB_Acl::getInstance()->isAllowed('use_screening_questionnaires')) { $questionnaireInfo = $questionnaireInfo ? $questionnaireInfo : array(); $questionnaireInfo = array_merge($questionnaireInfo, $_REQUEST); $questionnaire = new SJB_ScreeningQuestionnaires($questionnaireInfo); if ($submit) { $questionnaire->addProperty(array('id' => 'user_sid', 'type' => 'id', 'value' => SJB_UserManager::getCurrentUserSID(), 'is_system' => true)); } if (isset($sid) && !is_null($sid)) { $questionnaire->setSID($sid); } $addForm = new SJB_Form($questionnaire); $addForm->registerTags($tp); switch ($submit) { case 'add': if ($addForm->isDataValid($errors)) { SJB_ScreeningQuestionnaires::save($questionnaire); SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . "/screening-questionnaires/add-questions/{$questionnaire->sid}/"); } else { $action = 'add'; $questionnaire->deleteProperty('user_sid'); $addForm = new SJB_Form($questionnaire); $addForm->registerTags($tp); } break; case 'edit': if ($addForm->isDataValid($errors)) { SJB_ScreeningQuestionnaires::save($questionnaire); SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . "/screening-questionnaires/edit/{$questionnaire->sid}/?edit=1"); } else { $tp->assign('sid', $_REQUEST['sid']); $questionnaire->deleteProperty('user_sid'); $addForm = new SJB_Form($questionnaire); $addForm->registerTags($tp); $action = 'edit'; } break; } $form_fields = $addForm->getFormFieldsInfo(); $tp->assign('form_fields', $form_fields); $metaDataProvider = SJB_ObjectMother::getMetaDataProvider(); $tp->assign('METADATA', array('form_fields' => $metaDataProvider->getFormFieldsMetadata($form_fields))); $tp->assign('edit', $edit); $tp->assign('request', $questionnaireInfo); $tp->assign('sid', $sid); $tp->assign('action', $action); $tp->assign('errors', $errors); $tp->display($template); } } }