Beispiel #1
0
 function showEditVariableRes($suid, $vsid)
 {
     $survey = new Survey($suid);
     $var = $survey->getVariableDescriptive($vsid);
     $texttype = loadvar("texttype");
     $value = loadvarAllowHTML("text");
     switch ($texttype) {
         case SETTING_QUESTION:
             $var->setQuestion($value);
             break;
         case SETTING_PRETEXT:
             $var->setPretext($value);
             break;
         case SETTING_POSTTEXT:
             $var->setPostText($value);
             break;
         case SETTING_OPTIONS:
             $code = loadvar("answercode");
             $current = explode("\r\n", $var->getOptionsText());
             foreach ($current as $k => $c) {
                 if (startsWith($c, $code . " ")) {
                     $current[$k] = $code . ' ' . $value;
                     break;
                 }
             }
             $var->setOptionsText(implode("\r\n", $current));
         default:
             break;
     }
     $var->save();
     $compiler = new Compiler($suid, getSurveyVersion($survey));
     $mess = $compiler->generateVariableDescriptives(array($var));
     $mess = $compiler->generateGetFills(array($var));
     $mess = $compiler->generateInlineFields(array($var));
 }
 function showEditGroupGeneral($group)
 {
     $returnStr = '<form id="editform" method="post">';
     if ($group->getGid() != "") {
         $returnStr .= $this->getGroupTopTab(0);
     } else {
         $group->setTemplate(loadvarAllowHTML(SETTING_GROUP_TEMPLATE));
         if ($group->getTemplate() == TABLE_TEMPLATE_CUSTOM) {
             $group->setCustomTemplate(loadvarAllowHTML(SETTING_GROUP_CUSTOM_TEMPLATE));
         }
     }
     $returnStr .= $this->displayComboBox();
     $returnStr .= '<div class="well">';
     $returnStr .= setSessionParamsPost(array('page' => 'sysadmin.survey.editgroupgeneralres', 'gid' => $group->getGid()));
     $returnStr .= '<table>';
     $returnStr .= '<tr><td>' . Language::labelTypeEditGeneralGroupName() . '</td><td><input type="text" class="form-control" name="' . SETTING_GROUP_NAME . '" value="' . convertHTLMEntities($group->getName(), ENT_QUOTES) . '"></td></tr>';
     $opendir = opendir(getBase() . DIRECTORY_SEPARATOR . "templates");
     if ($opendir) {
         $returnStr .= '<tr><td>' . Language::labelTypeEditGeneralGroupTemplate() . '</td><td>
                         <select class="selectpicker show-tick" id="' . SETTING_GROUP_TEMPLATE . '" name="' . SETTING_GROUP_TEMPLATE . '">';
         $templates = Common::surveyTemplates();
         $current = $group->getTemplate();
         if ($current == "") {
             $current = TABLE_TEMPLATE_DEFAULT;
         }
         while (false !== ($entry = readdir($opendir))) {
             if (!is_dir($entry)) {
                 $entry = str_replace(".php", "", $entry);
                 if (inArray($entry, array_keys($templates))) {
                     $selected = "";
                     if (strtoupper($entry) == strtoupper($current)) {
                         $selected = "SELECTED";
                     }
                     $returnStr .= "<option {$selected} value='" . $entry . "'>" . $templates[$entry] . "</option>";
                 }
             }
         }
         $returnStr .= '</select>    
                         </td></tr>';
     }
     if ($group->getTemplate() == TABLE_TEMPLATE_CUSTOM) {
         $returnStr .= "<tr id=customtemplate><td>" . Language::labelTypeEditEnumeratedCustom() . "</td>";
     } else {
         $returnStr .= "<tr id=customtemplate style='display: none;'><td>" . Language::labelTypeEditEnumeratedCustom() . "</td>";
     }
     $returnStr .= '<td colspan=4><textarea style="width: 700px;" rows=20 class="form-control autocomplete" name="' . SETTING_GROUP_CUSTOM_TEMPLATE . '">' . $this->displayTextSettingValue(convertHTLMEntities($group->getCustomTemplate(), ENT_QUOTES)) . '</textarea></td></tr>';
     $returnStr .= "<script type='text/javascript'>";
     $returnStr .= '$( document ).ready(function() {
                                                 $("#' . SETTING_GROUP_TEMPLATE . '").change(function (e) {
                                                     if (this.value == "' . TABLE_TEMPLATE_CUSTOM . '") {
                                                         $("#customtemplate").show();                                                           
                                                     }  
                                                     else {                                                            
                                                         $("#customtemplate").hide();
                                                     }                                                        
                                                 });
                                                 })';
     $returnStr .= "</script>";
     if (Config::xiExtension()) {
         $returnStr .= '<tr><td>' . Language::labelTypeEditGeneralGroupXiTemplate() . '</td><td>
                         <select class="selectpicker show-tick" id="' . SETTING_GROUP_XI_TEMPLATE . '" name="' . SETTING_GROUP_XI_TEMPLATE . '">';
         $current = $group->getXiTemplate();
         if (file_exists(getBase() . DIRECTORY_SEPARATOR . "templates" . DIRECTORY_SEPARATOR . "xitemplates.php")) {
             $xitemplates = file_get_contents(getBase() . DIRECTORY_SEPARATOR . "templates" . DIRECTORY_SEPARATOR . "xitemplates.php", "r");
             $list = explode(");", $xitemplates);
             foreach ($list as $l) {
                 if (contains($l, " new Template")) {
                     $sub = explode("=", $l);
                     $selected = "";
                     $entry = trim(str_replace("\$", "", $sub[0]));
                     if (strtoupper($entry) == strtoupper($current)) {
                         $selected = "SELECTED";
                     }
                     $returnStr .= "<option {$selected} value='" . $entry . "'>" . $entry . "</option>";
                 }
             }
         }
         $returnStr .= '</select>    
                         </td></tr>';
     }
     $returnStr .= '</table></div>';
     if ($group->getName() != "") {
         $returnStr .= '<input type="submit" class="btn btn-default" value="' . Language::buttonEdit() . '"/>';
     } else {
         $returnStr .= '<input type="submit" class="btn btn-default" value="' . Language::buttonAdd() . '"/>';
     }
     $returnStr .= '</form>';
     return $returnStr;
 }
Beispiel #3
0
 function handleGroupAction($selected, $action, &$groupcookievalue)
 {
     $surveys = array();
     $displaySysAdmin = new DisplaySysAdmin();
     switch ($action) {
         case 'edit':
             $settings = $this->getBatchEditorGroupProperties();
             $tosave = array();
             $tocompile = array();
             $changed = array();
             foreach ($settings as $set) {
                 if (loadvar($set . "_checkbox") == 1) {
                     $val = loadvarAllowHTML($set);
                     if ($val != "") {
                         foreach ($selected as $sel) {
                             $s = explode("~", $sel);
                             if (isset($surveys[$s[0]])) {
                                 $survey = $surveys[$s[0]];
                             } else {
                                 $survey = new Survey($s[0]);
                                 $surveys[$s[0]] = $survey;
                                 $tocompile[] = $s[0];
                             }
                             if (isset($tosave[$sel])) {
                                 $group = $tosave[$sel];
                             } else {
                                 $group = $survey->getGroup($s[1]);
                                 $tosave[$sel] = $group;
                             }
                             if (isset($changed[$s[0]])) {
                                 $arr = $changed[$s[0]];
                                 if (isset($arr[$sel]) == false) {
                                     $arr[$sel] = $group;
                                     $changed[$s[0]] = $arr;
                                 }
                             } else {
                                 $arr = array();
                                 $arr[$sel] = $group;
                                 $changed[$s[0]] = $arr;
                             }
                             $group->setSettingValue($set, $val);
                             if ($set == SETTING_GROUP_TEMPLATE && $val == TABLE_TEMPLATE_CUSTOM) {
                                 $group->setSettingValue(SETTING_GROUP_CUSTOM_TEMPLATE, loadvarAllowHTML(SETTING_GROUP_CUSTOM_TEMPLATE));
                             }
                         }
                     }
                 }
             }
             /* save */
             foreach ($tosave as $to) {
                 $to->save();
             }
             /* compile */
             foreach ($tocompile as $comp) {
                 if (isset($surveys[$comp])) {
                     $survey = $surveys[$comp];
                 } else {
                     $survey = new Survey($comp);
                     $surveys[$comp] = $survey;
                 }
                 $compiler = new Compiler($comp, getSurveyVersion($surveys[$comp]));
                 $mess = $compiler->generateGroups($changed[$comp]);
                 $mess = $compiler->generateGetFillsGroups($changed[$comp]);
                 $mess = $compiler->generateInlineFieldsGroups($changed[$comp]);
             }
             if ($changed) {
                 $content = $displaySysAdmin->displaySuccess(Language::messageToolsBatchEditorEdited(Language::labelGroupsLower()));
             } else {
                 $content = $displaySysAdmin->displayWarning(Language::messageToolsBatchEditorNotEdited());
             }
             break;
             break;
         case 'copy':
             // determine survey
             $suid = loadvar('suid');
             foreach ($selected as $sel) {
                 $s = explode("~", $sel);
                 if (isset($surveys[$s[0]])) {
                     $survey = $surveys[$s[0]];
                 } else {
                     $survey = new Survey($s[0]);
                     $surveys[$s[0]] = $survey;
                 }
                 $group = $survey->getGroup($s[1]);
                 $oldgroup = $group;
                 $group->copy($suid);
                 $newgroups[] = $group;
             }
             /* compile new */
             $compiler = new Compiler($suid, getSurveyVersion($survey));
             $mess = $compiler->generateGroups($newgroups);
             $mess = $compiler->generateGetFillsGroups($newgroups);
             $mess = $compiler->generateInlineFieldsGroups($newgroups);
             $content = $displaySysAdmin->displaySuccess(Language::messageToolsBatchEditorCopied(Language::labelGroupsLower()));
             break;
         case 'move':
             $tocompile = array();
             $moved = array();
             $newgroups = array();
             // determine survey
             $suid = loadvar('suid');
             $cookiearr = explode("-", $groupcookievalue);
             foreach ($selected as $sel) {
                 $s = explode("~", $sel);
                 if (isset($surveys[$s[0]])) {
                     $survey = $surveys[$s[0]];
                 } else {
                     $survey = new Survey($s[0]);
                     $surveys[$s[0]] = $survey;
                     $tocompile[] = $s[0];
                 }
                 $group = $survey->getGroup($s[1]);
                 $oldgroup = $group;
                 $group->move($suid);
                 if (isset($moved[$s[0]])) {
                     $arr = $moved[$s[0]];
                 } else {
                     $arr = array();
                 }
                 $arr[] = $oldgroup;
                 $moved[$s[0]] = $arr;
                 $newgroups[] = $group;
                 /* update cookie */
                 $ind = array_search($sel, $cookiearr);
                 $cookiearr[$ind] = $group->getSuid() . '~' . $group->getGid();
             }
             /* update cookie */
             setcookie('uscicgroupcookie', implode("-", $cookiearr));
             //implode("-", $arr));
             $groupcookievalue = implode("-", $cookiearr);
             /* compile old */
             foreach ($tocompile as $comp) {
                 if (isset($surveys[$comp])) {
                     $survey = $surveys[$comp];
                 } else {
                     $survey = new Survey($comp);
                     $surveys[$comp] = $survey;
                 }
                 /* we moved across survey for one or more groups in this survey */
                 if ($suid != $comp) {
                     $compiler = new Compiler($comp, getSurveyVersion($surveys[$comp]));
                     $mess = $compiler->generateGroups($moved[$comp], true);
                 }
             }
             /* compile new */
             $compiler = new Compiler($suid, getSurveyVersion($survey));
             $mess = $compiler->generateGroups($newgroups);
             $mess = $compiler->generateGetFillsGroups($newgroups);
             $mess = $compiler->generateInlineFieldsGroups($newgroups);
             $content = $displaySysAdmin->displaySuccess(Language::messageToolsBatchEditorMoved(Language::labelGroupsLower()));
             break;
         case 'remove':
             $removed = array();
             $cookiearr = explode("-", $groupcookievalue);
             foreach ($selected as $sel) {
                 $s = explode("~", $sel);
                 if (isset($surveys[$s[0]])) {
                     $survey = $surveys[$s[0]];
                 } else {
                     $survey = new Survey($s[0]);
                     $surveys[$s[0]] = $survey;
                 }
                 $group = $survey->getGroup($s[1]);
                 $group->remove();
                 $removed[] = $group;
                 /* update cookie */
                 $ind = array_search($sel, $cookiearr);
                 unset($cookiearr[$ind]);
             }
             /* update cookie */
             setcookie('uscicgroupcookie', implode("-", $cookiearr));
             //implode("-", $arr));
             $groupcookievalue = implode("-", $cookiearr);
             /* compile */
             foreach ($surveys as $survey) {
                 $compiler = new Compiler($survey->getSuid(), getSurveyVersion($survey));
                 $mess = $compiler->generateGroups($removed, true);
             }
             $content = $displaySysAdmin->displaySuccess(Language::messageToolsBatchEditorRemoved(Language::labelGroupsLower()));
             break;
         default:
             $content = $displaySysAdmin->displayWarning(Language::messageToolsBatchEditorUnrecognizedAction());
             break;
     }
     return $content;
 }
Beispiel #4
0
 function showTranslateGroupAssistanceRes()
 {
     $displayTranslator = new DisplayTranslator();
     $survey = new Survey($_SESSION['SUID']);
     $gid = getFromSessionParams('gid');
     $group = $survey->getGroup($gid);
     $_SESSION['GID'] = $gid;
     $group->setEmptyMessage(loadvarAllowHTML(SETTING_EMPTY_MESSAGE));
     $group->setErrorMessageExactRequired(loadvarAllowHTML(SETTING_ERROR_MESSAGE_EXACT_REQUIRED));
     $group->setErrorMessageMinimumRequired(loadvarAllowHTML(SETTING_ERROR_MESSAGE_MINIMUM_REQUIRED));
     $group->setErrorMessageMaximumRequired(loadvarAllowHTML(SETTING_ERROR_MESSAGE_MAXIMUM_REQUIRED));
     $group->setErrorMessageExclusive(loadvarAllowHTML(SETTING_ERROR_MESSAGE_EXCLUSIVE));
     $group->setErrorMessageInclusive(loadvarAllowHTML(SETTING_ERROR_MESSAGE_INCLUSIVE));
     $group->SetErrorMessageUniqueRequired(loadvarAllowHTML(SETTING_ERROR_MESSAGE_UNIQUE_REQUIRED));
     $content = $displayTranslator->displaySuccess(Language::messageGroupChanged($group->getName()));
     $group->save();
     /* compile */
     $compiler = new Compiler($_SESSION['SUID'], getSurveyVersion($survey));
     $mess = $compiler->generateGroups(array($group));
     $mess = $compiler->generateGetFillsGroups(array($group));
     /* update last page */
     $_SESSION['LASTPAGE'] = substr($_SESSION['LASTPAGE'], 0, strripos($_SESSION['LASTPAGE'], "res"));
     /* return result */
     return $displayTranslator->showTranslateGroup($_SESSION['GID'], $content);
 }