/**
  * Save question answer
  *
  * @param
  * @return
  */
 function saveQuestionAnswer($a_type, $a_id, $a_answer)
 {
     global $ilUser, $ilLog, $ilDB;
     //$a_type = "assOrderingQuestion";
     //$a_id = 74;
     //$a_answer = '{"tries":1,"wrong":2,"passed":false,"answer":[true,true,false,true,false],"interactionId":null,"choice":["1","2","5","4","3"]}';
     $ilLog->write($a_type);
     $ilLog->write($a_id);
     $ilLog->write($a_answer);
     include_once "./Services/JSON/classes/class.ilJsonUtil.php";
     $answer = ilJsonUtil::decode($a_answer);
     $tries = $answer->tries;
     $passed = $answer->passed;
     $choice = $answer->choice;
     $points = ilPageQuestionProcessor::calculatePoints($a_type, $a_id, $choice);
     $ilLog->write("Points: " . $points);
     $set = $ilDB->query("SELECT * FROM page_qst_answer WHERE " . " qst_id = " . $ilDB->quote($a_id, "integer") . " AND " . " user_id = " . $ilDB->quote($ilUser->getId(), "integer"));
     if ($rec = $ilDB->fetchAssoc($set)) {
         $ilDB->manipulate("UPDATE page_qst_answer SET " . " try = try + 1," . " passed = " . $ilDB->quote($passed, "integer") . "," . " points = " . $ilDB->quote($points, "float") . " WHERE qst_id = " . $ilDB->quote($a_id, "integer") . " AND user_id = " . $ilDB->quote($ilUser->getId(), "integer"));
     } else {
         $ilDB->manipulate("INSERT INTO page_qst_answer " . "(qst_id, user_id, try, passed, points) VALUES (" . $ilDB->quote($a_id, "integer") . "," . $ilDB->quote($ilUser->getId(), "integer") . "," . $ilDB->quote(1, "integer") . "," . $ilDB->quote($passed, "integer") . "," . $ilDB->quote($points, "float") . ")");
     }
     //$ilLog->write("tries: ".$tries);
     //$ilLog->write("passed: ".$passed);
     //$ilLog->write("points: ".$points);
     exit;
 }
 /**
  * Get list of roles assigned to an object
  * @return 
  * @param object $result
  */
 public static function getListByObject($a_str)
 {
     global $rbacreview, $ilDB;
     include_once './Services/JSON/classes/class.ilJsonUtil.php';
     $result = array();
     if (strpos($a_str, '@') !== 0) {
         return ilJsonUtil::encode($result);
     }
     $a_str = substr($a_str, 1);
     $ilDB->setLimit(100);
     $query = "SELECT ref_id, title FROM object_data ode " . "JOIN object_reference ore ON ode.obj_id = ore.obj_id " . "WHERE " . $ilDB->like('title', 'text', $a_str . '%') . ' ' . 'ORDER BY title';
     $res = $ilDB->query($query);
     $counter = 0;
     while ($row = $res->fetchRow(DB_FETCHMODE_OBJECT)) {
         $rolf = $rbacreview->getRoleFolderIdOfObject($row->ref_id);
         if ($rolf) {
             foreach ($rbacreview->getRolesOfRoleFolder($rolf, false) as $rol_id) {
                 $role = ilObject::_lookupTitle($rol_id);
                 $result[$counter] = new stdClass();
                 $result[$counter]->value = $role;
                 $result[$counter]->label = $role . " (" . $row->title . ")";
                 ++$counter;
             }
         }
     }
     return ilJsonUtil::encode($result);
 }
 /**
  * Get completion list
  */
 static function getList($a_str)
 {
     global $ilDB;
     $a_str = str_replace('"', "", $a_str);
     $settings = new ilSearchSettings();
     $object_types = array('cat', 'dbk', 'crs', 'fold', 'frm', 'grp', 'lm', 'sahs', 'glo', 'mep', 'htlm', 'exc', 'file', 'qpl', 'tst', 'svy', 'spl', 'chat', 'icrs', 'icla', 'webr', 'mcst', 'sess', 'pg', 'st', 'gdf', 'wiki');
     $set = $ilDB->query("SELECT title, obj_id FROM object_data WHERE " . $ilDB->like('title', 'text', $a_str . "%") . " AND " . $ilDB->in('type', $object_types, false, 'text') . " ORDER BY title");
     $max = $settings->getAutoCompleteLength() > 0 ? $settings->getAutoCompleteLength() : 10;
     $cnt = 0;
     $list = array();
     $checked = array();
     $lim = "";
     while (($rec = $ilDB->fetchAssoc($set)) && $cnt < $max) {
         if (strpos($rec["title"], " ") > 0 || strpos($rec["title"], "-") > 0) {
             $rec["title"] = '"' . $rec["title"] . '"';
         }
         if (!in_array($rec["title"], $list) && !in_array($rec["obj_id"], $checked)) {
             if (ilSearchAutoComplete::checkObjectPermission($rec["obj_id"])) {
                 $list[] = $lim . $rec["title"];
                 $cnt++;
             }
             $checked[] = $rec["obj_id"];
         }
     }
     $set = $ilDB->query("SELECT rbac_id,obj_id,obj_type, keyword FROM il_meta_keyword WHERE " . $ilDB->like('keyword', 'text', $a_str . "%") . " AND " . $ilDB->in('obj_type', $object_types, false, 'text') . " ORDER BY keyword");
     while (($rec = $ilDB->fetchAssoc($set)) && $cnt < $max) {
         if (strpos($rec["keyword"], " ") > 0) {
             $rec["keyword"] = '"' . $rec["keyword"] . '"';
         }
         if (!in_array($rec["keyword"], $list) && !in_array($rec["rbac_id"], $checked)) {
             if (ilSearchAutoComplete::checkObjectPermission($rec["rbac_id"])) {
                 $list[] = $lim . $rec["keyword"];
                 $cnt++;
             }
         }
         $checked[] = $rec["rbac_id"];
     }
     $i = 0;
     $result = array();
     foreach ($list as $l) {
         $result[$i] = new stdClass();
         $result[$i]->value = $l;
         $i++;
     }
     include_once './Services/JSON/classes/class.ilJsonUtil.php';
     return ilJsonUtil::encode($result);
 }
 /**
  * @return \Dropbox\Config
  */
 public function getAuth()
 {
     if (!$this->auth) {
         $app_info = new stdClass();
         $app_info->key = $this->getAdminConfigObject()->getAppKey();
         $app_info->secret = $this->getAdminConfigObject()->getAppSecret();
         $app_info->access_type = "AppFolder";
         $app_info->root = 'auto';
         $app_info = ilJsonUtil::encode($app_info);
         $info = \Dropbox\AppInfo::loadFromJson(json_decode($app_info, true));
         $client_identifier = $this->getAdminConfigObject()->getAppName();
         $token_store = new Dropbox\ArrayEntryStore($_SESSION, 'dropbox-auth-token');
         $redirect_uri = ILIAS_HTTP_PATH . '/Customizing/global/plugins/Modules/Cloud/CloudHook/Dropbox/redirect.php';
         $this->auth = new Dropbox\WebAuth($info, $client_identifier, $redirect_uri, $token_store);
     }
     return $this->auth;
 }
Example #5
0
 /**
  * Auto complete for insert wiki link
  */
 function insertWikiLinkAC()
 {
     $result = array();
     $term = $_GET["term"];
     // if page exists, make it first entry
     if (ilWikiPage::_wikiPageExists($this->getPageObject()->getParentId(), $term)) {
         $entry = new stdClass();
         $entry->value = $term;
         $entry->label = $term;
         $result[] = $entry;
     }
     $res = ilWikiPage::getPagesForSearch($this->getPageObject()->getParentId(), $term);
     $cnt = 0;
     foreach ($res as $r) {
         if ($result[0]->value == $r) {
             continue;
         }
         if ($cnt++ > 19) {
             continue;
         }
         $entry = new stdClass();
         $entry->value = $r;
         $entry->label = $r;
         $result[] = $entry;
     }
     include_once './Services/JSON/classes/class.ilJsonUtil.php';
     echo ilJsonUtil::encode($result);
     exit;
 }
 public function lookupRecipientAsync()
 {
     include_once 'Services/JSON/classes/class.ilJsonUtil.php';
     include_once 'Services/Mail/classes/class.ilMailForm.php';
     $search = $_REQUEST["term"];
     $result = array();
     if (!$search) {
         echo ilJsonUtil::encode($result);
         exit;
     }
     // #14768
     $quoted = ilUtil::stripSlashes($search);
     $quoted = str_replace('%', '\\%', $quoted);
     $quoted = str_replace('_', '\\_', $quoted);
     $search_recipients = $_GET["ref"] != "wsp";
     $mailFormObj = new ilMailForm();
     $result = $mailFormObj->getRecipientAsync("%" . $quoted . "%", ilUtil::stripSlashes($search), $search_recipients);
     echo ilJsonUtil::encode($result);
     exit;
 }
 public function fillTreeTemplate()
 {
     $emptyOnLoad = false;
     $nodes_to_request = $_SESSION['frm'][(int) $this->topic->getId()]['openTreeNodes'];
     if (!$_SESSION['frm'][(int) $this->topic->getId()]['openTreeNodes'] || count($_SESSION['frm'][(int) $this->topic->getId()]['openTreeNodes']) == 1 && $_SESSION['frm'][(int) $this->topic->getId()]['openTreeNodes'][0] == 0) {
         $emptyOnLoad = true;
         $nodes_to_request = array();
     }
     $objects = $this->topic->getNestedSetPostChildren(null, $nodes_to_request);
     $counter = 0;
     $onloadNodes = array();
     $nodesFetchedWithChildren = array();
     $frm = new ilForum();
     $pageHits = $frm->getPageHits();
     include_once 'Services/JSON/classes/class.ilJsonUtil.php';
     foreach ($objects as $object) {
         if ($object['pos_pk'] != $this->root_id && !in_array($object['parent_pos'], $onloadNodes)) {
             continue;
         }
         if (in_array((int) $object['parent_pos'], $onloadNodes) && !in_array((int) $object['parent_pos'], $nodesFetchedWithChildren)) {
             $nodesFetchedWithChildren[] = (int) $object['parent_pos'];
         }
         $html = self::getTreeNodeHtml($object, $this->gui, $pageHits);
         $hasChildren = $object['children'] >= 1;
         $node = new stdClass();
         $node->html = $html;
         if ($object['pos_pk'] == $this->root_id) {
             $this->tpl->setVariable('FRM_TREE_ROOT_NODE_VARIABLE', 'frmNode' . $object['pos_pk']);
             $this->tpl->setVariable('FRM_TREE_ROOT_NODE_LINK', ilJsonUtil::encode($node));
             $this->tpl->setVariable('FRM_TREE_ROOT_NODE_HAS_CHILDREN', $hasChildren ? 'true' : 'false');
         } else {
             $this->tpl->setCurrentBlock('frm_nodes');
             $this->tpl->setVariable('FRM_NODES_VARNAME', 'frmNode' . $object['pos_pk']);
             $this->tpl->setVariable('FRM_NODES_PARENT_VARNAME', 'frmNode' . $object['parent_pos']);
             $this->tpl->setVariable('FRM_NODES_LINK', ilJsonUtil::encode($node));
             $this->tpl->setVariable('FRM_NODES_HAS_CHILDREN', $hasChildren ? 'true' : 'false');
             $this->tpl->parseCurrentBlock();
         }
         $onloadNodes[] = (int) $object['pos_pk'];
         ++$counter;
     }
     $this->tpl->setVariable('THR_ONLOAD_NODES', ilJsonUtil::encode($onloadNodes));
     $this->tpl->setVariable('THR_ONLOAD_NODES_FETCHED_WITH_CHILDREN', ilJsonUtil::encode($nodesFetchedWithChildren));
     if ($emptyOnLoad) {
         $this->tpl->setVariable('THR_OPEN_NODES', ilJsonUtil::encode($onloadNodes));
         $_SESSION['frm'][(int) $this->topic->getId()]['openTreeNodes'] = array_unique(array_merge(array(0), $onloadNodes));
     } else {
         $this->tpl->setVariable('THR_OPEN_NODES', ilJsonUtil::encode($_SESSION['frm'][(int) $this->topic->getId()]['openTreeNodes']));
     }
 }
 protected function doProfileAutoComplete()
 {
     $field_id = (string) $_REQUEST["f"];
     $term = (string) $_REQUEST["term"];
     $result = self::getAutocompleteResult($field_id, $term);
     include_once 'Services/JSON/classes/class.ilJsonUtil.php';
     echo ilJsonUtil::encode($result);
     exit;
 }
 protected function addDropZone()
 {
     $options = new stdClass();
     $options->dropZone = ".ilFileUploadDropZone_1";
     $options->fileInput = "#ilFileUploadInput_1";
     $options->submitButton = "uploadFiles";
     $options->cancelButton = "cancelAll";
     $options->dropArea = ".ilFileDropTarget";
     $options->fileList = "#ilFileUploadList_1";
     $options->fileSelectButton = "#ilFileUploadFileSelect_1";
     echo "<script language='javascript' type='text/javascript'>var fileUpload1 = new ilFileUpload(1, " . ilJsonUtil::encode($options) . ");</script>";
 }
 /**
  * Makes an existing HTML element an overlay 
  */
 function getOnLoadCode()
 {
     // yui cfg string
     $yuicfg["visible"] = $this->visible ? true : false;
     if ($this->width != "") {
         $yuicfg["width"] = $this->width;
     }
     if ($this->height != "") {
         $yuicfg["height"] = $this->height;
     }
     $yuicfg["fixedcenter"] = $this->fixed_center ? true : false;
     if ($this->anchor_el_id != "") {
         $yuicfg["context"] = array($this->anchor_el_id, $this->anchor_ov_corner, $this->anchor_anch_corner, array("beforeShow", "windowResize"));
     }
     // general cfg string
     $cfg["yuicfg"] = $yuicfg;
     $cfg["trigger"] = $this->trigger_el_id;
     $cfg["trigger_event"] = $this->trigger_event;
     $cfg["anchor_id"] = $this->trigger_anchor_el_id;
     $cfg["auto_hide"] = $this->auto_hide;
     $cfg["close_el"] = $this->close_el;
     include_once "./Services/JSON/classes/class.ilJsonUtil.php";
     //var_dump(ilJsonUtil::encode($cfg));
     return 'il.Overlay.add("' . $this->overlay_el_id . '", ' . ilJsonUtil::encode($cfg) . '); ';
 }
Example #11
0
 public function asyncGetBlock()
 {
     global $tpl;
     $response = new stdClass();
     $response->message = NULL;
     $response->locator = NULL;
     $response->content = NULL;
     $response->success = NULL;
     try {
         $file_tree = ilCloudFileTree::getFileTreeFromSession();
         $file_tree->updateFileTree($_POST["path"]);
         $node = $file_tree->getNodeFromPath($_POST["path"]);
         $file_tree_gui = ilCloudConnector::getFileTreeGUIClass($this->plugin_service, $file_tree);
         $response->content = $file_tree_gui->getFolderHtml($this, $node->getId(), $this->checkPermissionBool("delete_files"), $this->checkPermissionBool("delete_folders"), $this->checkPermissionBool("download"), $this->checkPermissionBool("files_visible"), $this->checkPermissionBool("folders_visible"));
         $response->locator = $file_tree_gui->getLocatorHtml($file_tree->getNodeFromId($node->getId()));
         $response->success = true;
     } catch (Exception $e) {
         $response->message = $tpl->getMessageHTML($e->getMessage(), "failure");
     }
     header('Content-type: application/json');
     echo ilJsonUtil::encode($response);
     exit;
 }
 protected function doProfileAutoComplete()
 {
     $field_id = (string) $_REQUEST["f"];
     $term = (string) $_REQUEST["term"];
     include_once "Services/User/classes/class.ilPublicUserProfileGUI.php";
     $result = ilPublicUserProfileGUI::getAutocompleteResult($field_id, $term);
     if (sizeof($result)) {
         include_once 'Services/JSON/classes/class.ilJsonUtil.php';
         echo ilJsonUtil::encode($result);
     }
     exit;
 }
Example #13
0
 /**
  * Get accordion html
  */
 function getHTML()
 {
     global $ilUser;
     self::$accordion_cnt++;
     $or_short = $this->getOrientation() == ilAccordionGUI::HORIZONTAL ? "H" : "V";
     $width = (int) $this->getContentWidth();
     $height = (int) $this->getContentHeight();
     if ($this->getOrientation() == ilAccordionGUI::HORIZONTAL) {
         if ($width == 0) {
             $width = 200;
         }
         if ($height == 0) {
             $height = 100;
         }
     }
     $this->addJavascript();
     $this->addCss();
     $tpl = new ilTemplate("tpl.accordion.html", true, true, "Services/Accordion");
     foreach ($this->getItems() as $item) {
         $tpl->setCurrentBlock("item");
         $tpl->setVariable("HEADER", $item["header"]);
         $tpl->setVariable("CONTENT", $item["content"]);
         $tpl->setVariable("HEADER_CLASS", $this->getHeaderClass() ? $this->getHeaderClass() : "il_" . $or_short . "AccordionHead");
         $tpl->setVariable("CONTENT_CLASS", $this->getContentClass() ? $this->getContentClass() : "il_" . $or_short . "AccordionContent");
         if ($this->getBehaviour() != self::FORCE_ALL_OPEN) {
             $tpl->setVariable("HIDE_CONTENT_CLASS", "ilAccHideContent");
         }
         $tpl->setVariable("OR_SHORT", $or_short);
         $tpl->setVariable("INNER_CONTAINER_CLASS", $this->getInnerContainerClass() ? $this->getInnerContainerClass() : "il_" . $or_short . "AccordionInnerContainer");
         if ($height > 0) {
             $tpl->setVariable("HEIGHT", "height:" . $height . "px;");
         }
         if ($height > 0 && $this->getOrientation() == ilAccordionGUI::HORIZONTAL) {
             $tpl->setVariable("HHEIGHT", "height:" . $height . "px;");
         }
         $tpl->parseCurrentBlock();
     }
     $tpl->setVariable("CONTAINER_CLASS", $this->getContainerClass() ? $this->getContainerClass() : "il_" . $or_short . "AccordionContainer");
     $options["orientation"] = $this->getOrientation();
     $options["int_id"] = $this->getId();
     if ($this->getUseSessionStorage() && $this->getId() != "") {
         include_once "./Services/Accordion/classes/class.ilAccordionPropertiesStorage.php";
         $stor = new ilAccordionPropertiesStorage();
         $ctab = $stor->getProperty($this->getId(), $ilUser->getId(), "opened");
         $ctab_arr = explode(";", $ctab);
         foreach ($this->force_open as $fo) {
             if (!in_array($fo, $ctab_arr)) {
                 $ctab_arr[] = $fo;
             }
         }
         $ctab = implode(";", $ctab_arr);
         if ($ctab == "0") {
             $ctab = "";
         }
         $options["initial_opened"] = $ctab;
         $options["save_url"] = "./ilias.php?baseClass=ilaccordionpropertiesstorage&cmd=setOpenedTab" . "&accordion_id=" . $this->getId() . "&user_id=" . $ilUser->getId();
     }
     $options["behaviour"] = $this->getBehaviour();
     if ($this->getOrientation() == ilAccordionGUI::HORIZONTAL) {
         $options["toggle_class"] = 'il_HAccordionToggleDef';
         $options["toggle_act_class"] = 'il_HAccordionToggleActiveDef';
         $options["content_class"] = 'il_HAccordionContentDef';
     } else {
         $options["toggle_class"] = 'il_VAccordionToggleDef';
         $options["toggle_act_class"] = 'il_VAccordionToggleActiveDef';
         $options["content_class"] = 'il_VAccordionContentDef';
     }
     if ($width > 0) {
         $options["width"] = $width;
     } else {
         $options["width"] = null;
     }
     if ($width > 0 && $this->getOrientation() == ilAccordionGUI::VERTICAL) {
         $tpl->setVariable("CWIDTH", 'style="width:' . $width . 'px;"');
     }
     if ($this->head_class_set) {
         $options["active_head_class"] = $this->getActiveHeaderClass();
     } else {
         if ($this->getOrientation() == ilAccordionGUI::VERTICAL) {
             $options["active_head_class"] = "il_HAccordionHeadActive";
         } else {
             $options["active_head_class"] = "il_VAccordionHeadActive";
         }
     }
     $options["height"] = null;
     $options["id"] = 'accordion_' . $this->getId() . '_' . self::$accordion_cnt;
     $options["multi"] = (bool) $this->getAllowMultiOpened();
     $options["show_all_element"] = $this->getShowAllElement();
     $options["hide_all_element"] = $this->getHideAllElement();
     include_once "./Services/JSON/classes/class.ilJsonUtil.php";
     $tpl->setVariable("OPTIONS", $str = ilJsonUtil::encode($options));
     $tpl->setVariable("ACC_ID", $options["id"]);
     //echo "<br><br><br><br><br><br>".$str;
     return $tpl->get();
 }
 /**
  * Gets the HTML code to enable the file upload.
  * 
  * @return string The created HTML.
  */
 public function getHTML()
 {
     global $lng, $ilCtrl, $tpl;
     // get values
     $id = $this->ref_id;
     // build options
     $options = new stdClass();
     $options->dropZone = $this->makeJqueryId($this->drop_zone_id);
     // set url
     $url = $this->getUploadUrl();
     if ($url === false) {
         return "";
     }
     if ($url != null) {
         $options->url = $this->getUploadUrl();
     }
     // get title and replace quotes with HTML entities
     if ($this->ref_id != null && !$this->use_form) {
         $title = ilObject::_lookupTitle(ilObject::_lookupObjId($this->ref_id));
         $title = str_replace("\"", "&quot;", $title);
         $title = str_replace("'", "&#039;", $title);
         $options->listTitle = $title;
     }
     // input field (use id if specified)
     if ($this->input_field_id != null) {
         $options->fileInput = $this->makeJqueryId($this->input_field_id);
     } else {
         if ($this->input_field_name != null) {
             $options->fileInput = $this->input_field_name;
         }
     }
     // buttons
     if ($this->submit_button_name != null) {
         $options->submitButton = $this->submit_button_name;
     }
     if ($this->cancel_button_name != null) {
         $options->cancelButton = $this->cancel_button_name;
     }
     // drop area
     if ($this->drop_area_id != null) {
         $options->dropArea = $this->makeJqueryId($this->drop_area_id);
     }
     // file list
     if ($this->file_list_id != null) {
         $options->fileList = $this->makeJqueryId($this->file_list_id);
     }
     // file list
     if ($this->file_select_button_id != null) {
         $options->fileSelectButton = $this->makeJqueryId($this->file_select_button_id);
     }
     // max size
     $max_size = $this->getMaxFileSize();
     if ($max_size != null) {
         $options->maxFileSize = $max_size;
     }
     // allowed extensions
     $allowed_suffixes = $this->buildSuffixList($this->getSuffixes());
     if ($allowed_suffixes != "") {
         $options->allowedExtensions = "[" . $allowed_suffixes . "]";
     }
     // supported archive extensions
     $supported_archives = $this->buildSuffixList($this->getArchiveSuffixes());
     if ($supported_archives != "") {
         $options->supportedArchives = "[" . $supported_archives . "]";
     }
     // inject load script
     include_once "./Services/JSON/classes/class.ilJsonUtil.php";
     $onLoadCode = "";
     if ($this->use_form) {
         $onLoadCode = "var fileUpload{$id} = new ilFileUpload({$id}, " . ilJsonUtil::encode($options) . ");";
     } else {
         $onLoadCode = "il.FileUpload.add(\"{$id}\", " . ilJsonUtil::encode($options) . ", " . ($this->current_obj ? "true" : "false") . ");";
     }
     $tpl->addOnLoadCode($onLoadCode);
     // return shared code
     return $this->getSharedHtml();
 }
 /**
  * Get completion list
  * @param string $a_str
  * @return string
  */
 public function getList($a_str)
 {
     /**
      * @var $ilDB  ilDB
      * @var $ilLog ilLog
      */
     global $ilDB, $ilLog;
     $select_part = $this->getSelectPart();
     $where_part = $this->getWherePart($a_str);
     $order_by_part = $this->getOrderByPart();
     $query = implode(" ", array('SELECT ' . $select_part, 'FROM ' . $this->getFromPart(), $where_part ? 'WHERE ' . $where_part : '', $order_by_part ? 'ORDER BY ' . $order_by_part : ''));
     $ilLog->write(__METHOD__ . ': Query: ' . $query);
     $res = $ilDB->query($query);
     // add email only if it is "searchable"
     $add_email = true;
     include_once 'Services/Search/classes/class.ilUserSearchOptions.php';
     if ($this->isFieldSearchableCheckEnabled() && !ilUserSearchOptions::_isEnabled("email")) {
         $add_email = false;
     }
     include_once './Services/Search/classes/class.ilSearchSettings.php';
     $max = $this->getLimit() ? $this->getLimit() : ilSearchSettings::getInstance()->getAutoCompleteLength();
     $cnt = 0;
     $more_results = FALSE;
     $result = array();
     while (($rec = $ilDB->fetchAssoc($res)) && $cnt < $max + 1) {
         if ($cnt >= $max) {
             $more_results = TRUE;
             break;
         }
         // @todo: Open discussion: We should remove all non public fields from result
         $label = $rec['lastname'] . ', ' . $rec['firstname'] . ' [' . $rec['login'] . ']';
         if ($add_email && $rec['email'] && (self::PRIVACY_MODE_RESPECT_USER_SETTING != $this->getPrivacyMode() || 'y' == $rec['email_value'])) {
             $label .= ', ' . $rec['email'];
         }
         $result[$cnt]['value'] = (string) $rec[$this->result_field];
         $result[$cnt]['label'] = $label;
         $result[$cnt]['id'] = $rec['usr_id'];
         $cnt++;
     }
     include_once 'Services/JSON/classes/class.ilJsonUtil.php';
     $result_json['items'] = $result;
     $result_json['hasMoreResults'] = $more_results;
     $GLOBALS['ilLog']->write(__METHOD__ . ': ' . print_r($result_json, TRUE));
     return ilJsonUtil::encode($result_json);
 }
    /**
     * @param int $sessionId
     * @return string
     */
    public function getJsonResponse($sessionId)
    {
        /**
         * @var $ilDB            ilDB
         * @var $ilUser          ilObjUser
         * @var $ilClientIniFile ilIniFile
         * @var $lng             ilLanguage
         */
        global $ilDB, $ilUser, $lng, $ilClientIniFile;
        include_once 'Services/JSON/classes/class.ilJsonUtil.php';
        $response = array('remind' => false);
        $res = $ilDB->queryF('
			SELECT expires, user_id, data
			FROM usr_session
			WHERE session_id = %s', array('text'), array($sessionId));
        $num = $ilDB->numRows($res);
        if ($num > 1) {
            $response['message'] = 'The determined session data is not unique.';
            return ilJsonUtil::encode($response);
        }
        if ($num == 0) {
            $response['message'] = 'ILIAS could not determine the session data.';
            return ilJsonUtil::encode($response);
        }
        $data = $ilDB->fetchAssoc($res);
        if (!$this->isAuthenticatedUsrSession($data)) {
            $response['message'] = 'ILIAS could not fetch the session data or the corresponding user is no more authenticated.';
            return ilJsonUtil::encode($response);
        }
        $session = ilUtil::unserializeSession($data['data']);
        $idletime = null;
        foreach ((array) $session as $key => $entry) {
            if (strpos($key, '_auth__') === 0) {
                $idletime = $entry['idle'];
                break;
            }
        }
        if (null === $idletime) {
            $response['message'] = 'ILIAS could not determine the idle time from the session data.';
            return ilJsonUtil::encode($response);
        }
        $expiretime = $idletime + ilSession::getIdleValue();
        if ($this->isSessionAlreadyExpired($expiretime)) {
            $response['message'] = 'The session is already expired. The client should have received a remind command before.';
            return ilJsonUtil::encode($response);
        }
        /**
         * @var $user ilObjUser
         */
        $ilUser = ilObjectFactory::getInstanceByObjId($data['user_id']);
        include_once './Services/Authentication/classes/class.ilSessionReminder.php';
        $remind_time = $expiretime - max(ilSessionReminder::MIN_LEAD_TIME, (double) $ilUser->getPref('session_reminder_lead_time')) * 60;
        if ($remind_time > time()) {
            // session will expire in <lead_time> minutes
            $response['message'] = 'Lead time not reached, yet. Current time: ' . date('Y-m-d H:i:s', time()) . ', Reminder time: ' . date('Y-m-d H:i:s', $remind_time);
            return ilJsonUtil::encode($response);
        }
        $dateTime = new ilDateTime($expiretime, IL_CAL_UNIX);
        switch ($ilUser->getTimeFormat()) {
            case ilCalendarSettings::TIME_FORMAT_12:
                $formatted_expiration_time = $dateTime->get(IL_CAL_FKT_DATE, 'g:ia', $ilUser->getTimeZone());
                break;
            case ilCalendarSettings::TIME_FORMAT_24:
            default:
                $formatted_expiration_time = $dateTime->get(IL_CAL_FKT_DATE, 'H:i', $ilUser->getTimeZone());
                break;
        }
        $response = array('extend_url' => './ilias.php?baseClass=ilPersonalDesktopGUI', 'txt' => str_replace("\\n", '%0A', sprintf($lng->txt('session_reminder_alert'), ilFormat::_secondsToString($expiretime - time()), $formatted_expiration_time, $ilClientIniFile->readVariable('client', 'name') . ' | ' . ilUtil::_getHttpPath())), 'remind' => true);
        return ilJsonUtil::encode($response);
    }
 public function lookupEmailsAsync()
 {
     include_once 'Services/JSON/classes/class.ilJsonUtil.php';
     include_once 'Services/Contact/classes/class.ilMailAddressbook.php';
     $search = "%" . $_REQUEST["term"] . "%";
     $mailAdrBookObj = new ilMailAddressbook();
     $result = $mailAdrBookObj->getEmailsAsync($search, $_REQUEST["term"]);
     echo ilJsonUtil::encode($result);
     exit;
 }
Example #18
0
 /**
  * Get json representation
  */
 final function getJsonRepresentation()
 {
     if ($this->version === false) {
         return false;
     }
     $arr["entity"] = $this->getJsonEntityName();
     $arr["version"] = $this->version;
     $arr["install_id"] = IL_INST_ID;
     $arr["install_url"] = ILIAS_HTTP_PATH;
     $arr["types"] = $this->getJsonTypes();
     $arr["set"] = array();
     foreach ($this->data as $d) {
         $arr["set"][] = $this->getJsonRecord($d);
     }
     include_once "./Services/JSON/classes/class.ilJsonUtil.php";
     return ilJsonUtil::encode($arr);
 }
 /**
  * Update properties
  */
 public function uploadFiles()
 {
     $response = new stdClass();
     $response->error = null;
     $response->debug = null;
     $this->initUploadForm();
     if ($this->form->checkInput()) {
         try {
             $fileresult = $this->handleFileUpload($this->form->getInput("upload_files"));
             if ($fileresult) {
                 $response = (object) array_merge((array) $response, (array) $fileresult);
             }
         } catch (ilException $e) {
             $response->error = $e->getMessage();
         }
     } else {
         $error = new ilCloudException(ilCloudException::UPLOAD_FAILED);
         $response->error = $error->getMessage();
     }
     // send response object (don't use 'application/json' as IE wants to download it!)
     header('Vary: Accept');
     header('Content-type: text/plain');
     echo ilJsonUtil::encode($response);
     exit;
 }
 public function lookupRecipientAsync()
 {
     include_once 'Services/JSON/classes/class.ilJsonUtil.php';
     include_once 'Services/Mail/classes/class.ilMailForm.php';
     $search = $_REQUEST["term"];
     $result = array();
     if (!$search) {
         echo ilJsonUtil::encode($result);
         exit;
     }
     $mailFormObj = new ilMailForm();
     $result = $mailFormObj->getRecipientAsync("%" . $search . "%", $search);
     echo ilJsonUtil::encode($result);
     exit;
 }
Example #21
0
 /**
  * Called after a file was uploaded.
  */
 public function uploadFiles()
 {
     include_once "./Services/JSON/classes/class.ilJsonUtil.php";
     $response = new stdClass();
     $response->error = null;
     $response->debug = null;
     $files = $_FILES;
     // #14249 - race conditions because of concurrent uploads
     $after_creation_callback = (int) $_REQUEST["crtcb"];
     if ($after_creation_callback) {
         $this->after_creation_callback_objects = array();
         unset($_REQUEST["crtcb"]);
     }
     // load form
     $dnd_form_gui = $this->initMultiUploadForm();
     if ($dnd_form_gui->checkInput()) {
         try {
             if (!$this->checkPermissionBool("create", "", "file")) {
                 $response->error = $this->lng->txt("permission_denied");
             } else {
                 // handle the file
                 $fileresult = $this->handleFileUpload($dnd_form_gui->getInput("upload_files"));
                 if ($fileresult) {
                     $response = (object) array_merge((array) $response, (array) $fileresult);
                 }
             }
         } catch (Exception $ex) {
             $response->error = $ex->getMessage() . " ## " . $ex->getTraceAsString();
         }
     } else {
         $dnd_input = $dnd_form_gui->getItemByPostVar("upload_files");
         $response->error = $dnd_input->getAlert();
     }
     if ($after_creation_callback && sizeof($this->after_creation_callback_objects)) {
         foreach ($this->after_creation_callback_objects as $new_file_obj) {
             ilObject2GUI::handleAfterSaveCallback($new_file_obj, $after_creation_callback);
         }
         unset($this->after_creation_callback_objects);
     }
     // send response object (don't use 'application/json' as IE wants to download it!)
     header('Vary: Accept');
     header('Content-type: text/plain');
     echo ilJsonUtil::encode($response);
     // no further processing!
     exit;
 }
 /**
  * @return string
  */
 public function __toString()
 {
     header("Content-type: application/json; charset=UTF-8");
     echo ilJsonUtil::encode($this->body);
     exit;
 }
 /**
  * Update properties
  */
 public function cancel()
 {
     $response = new stdClass();
     $response->status = "cancel";
     echo "<script language='javascript' type='text/javascript'>window.parent.il.CloudFileList.afterDeleteItem(" . ilJsonUtil::encode($response) . ");</script>";
     exit;
 }
Example #24
0
 public function fetchTreeChildrenAsyncObject()
 {
     include_once 'Services/JSON/classes/class.ilJsonUtil.php';
     include_once 'Modules/Forum/classes/class.ilForumExplorer.php';
     $response = new stdClass();
     $response->success = false;
     if ($_GET['nodeId']) {
         $response->success = true;
         $response->children = array();
         $key = array_search((int) $_GET['nodeId'], (array) $_SESSION['frm'][(int) $_GET['thr_pk']]['openTreeNodes']);
         if (false === $key) {
             $_SESSION['frm'][(int) $_GET['thr_pk']]['openTreeNodes'][] = (int) $_GET['nodeId'];
         }
         $children = $this->objCurrentTopic->getNestedSetPostChildren((int) $_GET['nodeId'], (array) $_SESSION['frm'][(int) $_GET['thr_pk']]['openTreeNodes']);
         $frm = new ilForum();
         $pageHits = $frm->getPageHits();
         $fetchedNodes = array();
         foreach ($children as $child) {
             if ($child['parent_pos'] != (int) $_GET['nodeId'] && !in_array($child['parent_pos'], $fetchedNodes)) {
                 continue;
             }
             $fetchedNodes[] = $child['pos_pk'];
             $this->ctrl->setParameter($this, 'thr_pk', (int) $_GET['thr_pk']);
             $html = ilForumExplorer::getTreeNodeHtml($child, $this, $pageHits);
             $responseChild = new stdClass();
             $responseChild->nodeId = $child['pos_pk'];
             $responseChild->parentId = $child['parent_pos'];
             $responseChild->hasChildren = $child['children'] >= 1;
             $responseChild->fetchedWithChildren = in_array((int) $child['pos_pk'], (array) $_SESSION['frm'][(int) $_GET['thr_pk']]['openTreeNodes']);
             $responseChild->html = $html;
             $response->children[] = $responseChild;
         }
     }
     echo ilJsonUtil::encode($response);
     exit;
 }
Example #25
0
 function keywordAutocomplete()
 {
     $force_all = (bool) $_GET["fetchall"];
     include_once "./Services/MetaData/classes/class.ilMDKeyword.php";
     $res = ilMDKeyword::_getMatchingKeywords(ilUtil::stripSlashes($_GET["term"]), "blp", $this->getParentObjId());
     include_once "./Services/Search/classes/class.ilSearchSettings.php";
     $cut = (int) ilSearchSettings::getInstance()->getAutoCompleteLength();
     $has_more = false;
     $result = array();
     foreach ($res as $r) {
         if (!$force_all && sizeof($result["items"]) >= $cut) {
             $has_more = true;
             break;
         }
         $entry = new stdClass();
         $entry->value = $r;
         $entry->label = $r;
         $result["items"][] = $entry;
     }
     $result["hasMoreResults"] = $has_more;
     include_once './Services/JSON/classes/class.ilJsonUtil.php';
     echo ilJsonUtil::encode($result);
     exit;
 }
 /**
  * Get selection list HTML
  */
 public function getHTML($a_only_cmd_list_asynch = false)
 {
     $items = $this->getItems();
     // do not show list, if no item is in list
     if (count($items) == 0 && !$this->getAsynch()) {
         return "";
     }
     include_once "./Services/YUI/classes/class.ilYuiUtil.php";
     ilYuiUtil::initOverlay();
     $GLOBALS["tpl"]->addJavascript("./Services/UIComponent/Overlay/js/ilOverlay.js");
     $GLOBALS["tpl"]->addJavascript("./Services/UIComponent/AdvancedSelectionList/js/AdvancedSelectionList.js");
     $tpl = new ilTemplate("tpl.adv_selection_list.html", true, true, "Services/UIComponent/AdvancedSelectionList", "DEFAULT", false, true);
     reset($items);
     $cnt = 0;
     if ($this->getAsynch()) {
         $tpl->setCurrentBlock("asynch_request");
         $tpl->setVariable("IMG_LOADER", ilUtil::getImagePath("loader.gif"));
         $tpl->parseCurrentBlock();
     } else {
         foreach ($items as $item) {
             if (isset($item["ref_id"])) {
                 $sel_arr[$item["ref_id"]] = isset($item["title"]) ? $item["title"] : "";
             }
             $this->css_row = $this->css_row != "tblrow1_mo" ? "tblrow1_mo" : "tblrow2_mo";
             if ($this->getUseImages()) {
                 if ($item["img"]) {
                     $tpl->setCurrentBlock("image");
                     $tpl->setVariable("IMG_ITEM", $item["img"]);
                     $tpl->setVariable("ALT_ITEM", $item["alt"]);
                     $tpl->parseCurrentBlock();
                 } else {
                     $tpl->touchBlock("no_image");
                 }
             }
             if ($this->getOnClickMode() == ilAdvancedSelectionListGUI::ON_ITEM_CLICK_HREF || $this->getItemLinkClass() != "") {
                 if ($item["frame"]) {
                     $tpl->setCurrentBlock("frame");
                     $tpl->setVariable("TARGET_ITEM", $item["frame"]);
                     $tpl->parseCurrentBlock();
                 }
                 if ($this->getItemLinkClass() != "") {
                     $tpl->setCurrentBlock("item_link_class");
                     $tpl->setVariable("ITEM_LINK_CLASS", $this->getItemLinkClass());
                     $tpl->parseCurrentBlock();
                 }
                 $tpl->setCurrentBlock("href_s");
                 $tpl->setVariable("HREF_ITEM", 'href="' . $item["link"] . '"');
                 $tpl->setVariable("ID_ITEM", $this->getId() . "_" . $item["value"]);
                 $tpl->parseCurrentBlock();
                 $tpl->touchBlock("href_e");
             }
             $tpl->setCurrentBlock("item");
             if ($this->getOnClickMode() == ilAdvancedSelectionListGUI::ON_ITEM_CLICK_HREF) {
                 if ($item["prevent_background_click"]) {
                     $tpl->setVariable("ONCLICK_ITEM", '');
                 } else {
                     if ($item["onclick"] == "") {
                         $tpl->setVariable("ONCLICK_ITEM", 'onclick="' . "return il.AdvancedSelectionList.openTarget('" . $item["link"] . "','" . $item["frame"] . "');" . '"');
                     } else {
                         $tpl->setVariable("ONCLICK_ITEM", 'onclick="' . "return " . $item["onclick"] . ";" . '"');
                     }
                 }
             } else {
                 if ($this->getOnClickMode() == ilAdvancedSelectionListGUI::ON_ITEM_CLICK_FORM_SUBMIT) {
                     $tpl->setVariable("ONCLICK_ITEM", 'onclick="return il.AdvancedSelectionList.submitForm(\'' . $this->getId() . '\'' . ", '" . $this->form_mode["select_name"] . "','" . $item["value"] . "'," . "'" . $this->on_click_form_id . "','" . $this->form_mode["button_cmd"] . "');\"");
                 } else {
                     if ($this->getOnClickMode() == ilAdvancedSelectionListGUI::ON_ITEM_CLICK_FORM_SELECT) {
                         $tpl->setVariable("ONCLICK_ITEM", 'onclick="return il.AdvancedSelectionList.selectForm(\'' . $this->getId() . '\'' . ", '" . $this->form_mode["select_name"] . "','" . $item["value"] . "'," . "'" . $item["title"] . "');\"");
                     } else {
                         if ($this->getOnClickMode() == ilAdvancedSelectionListGUI::ON_ITEM_CLICK_NOP) {
                             $tpl->setVariable("ONCLICK_ITEM", 'onclick="il.AdvancedSelectionList.clickNop(\'' . $this->getId() . '\'' . ", '" . $this->form_mode["select_name"] . "','" . $item["value"] . "'," . "'" . $item["title"] . "');\"");
                         }
                     }
                 }
             }
             $tpl->setVariable("CSS_ROW", $this->css_row);
             if ($item["html"] == "") {
                 $tpl->setVariable("TXT_ITEM", $item["title"]);
             } else {
                 $tpl->setVariable("TXT_ITEM", $item["html"]);
             }
             $tpl->setVariable("ID_ITEM_TR", $this->getId() . "_" . $item["value"] . "_tr");
             if ($item["ttip"] != "") {
                 include_once "./Services/UIComponent/Tooltip/classes/class.ilTooltipGUI.php";
                 ilTooltipGUI::addTooltip($this->getId() . "_" . $item["value"] . "_tr", $item["ttip"], "", $item["tt_my"], $item["tt_at"], $item["tt_use_htmlspecialchars"]);
             }
             $tpl->parseCurrentBlock();
             // add item to js object
             $tpl->setCurrentBlock("js_item");
             $tpl->setVariable("IT_ID", $this->getId());
             $tpl->setVariable("IT_HID_NAME", $this->form_mode["select_name"]);
             $tpl->setVariable("IT_HID_VAL", $item["value"]);
             $tpl->setVariable("IT_TITLE", str_replace("'", "\\'", $item["title"]));
             $tpl->parseCurrentBlock();
         }
     }
     $tpl->setCurrentBlock("cmd_table");
     $tpl->parseCurrentBlock();
     if ($a_only_cmd_list_asynch) {
         return $tpl->get("cmd_table");
     }
     if ($this->getHeaderIcon() != ilAdvancedSelectionListGUI::NO_ICON) {
         $tpl->setCurrentBlock("top_img");
         switch ($this->getHeaderIcon()) {
             case ilAdvancedSelectionListGUI::DOWN_ARROW_LIGHT:
                 $tpl->setVariable("IMG_DOWN", ilUtil::getImagePath(ilAdvancedSelectionListGUI::DOWN_ARROW_LIGHT));
                 break;
             case ilAdvancedSelectionListGUI::DOWN_ARROW_DARK:
                 $tpl->setVariable("IMG_DOWN", ilUtil::getImagePath(ilAdvancedSelectionListGUI::DOWN_ARROW_DARK));
                 break;
             case ilAdvancedSelectionListGUI::DOWN_ARROW_TOPBAR:
                 $tpl->setVariable("IMG_DOWN", ilUtil::getImagePath(ilAdvancedSelectionListGUI::DOWN_ARROW_TOPBAR));
                 break;
             default:
                 $tpl->setVariable("IMG_DOWN", $this->getHeaderIcon());
                 break;
         }
         // do not repeat title (accessibility) -> empty alt
         //$tpl->setVariable("ALT_SEL_TOP", $this->getListTitle());
         $tpl->setVariable("ALT_SEL_TOP", "");
         $tpl->parseCurrentBlock();
     }
     // output hidden input, if click mode is form submission
     if ($this->getOnClickMode() == ilAdvancedSelectionListGUI::ON_ITEM_CLICK_FORM_SUBMIT) {
         $tpl->setCurrentBlock("hidden_input");
         $tpl->setVariable("HID", $this->getId());
         $tpl->parseCurrentBlock();
     }
     // output hidden input and initialize
     if ($this->getOnClickMode() == ilAdvancedSelectionListGUI::ON_ITEM_CLICK_FORM_SELECT) {
         $tpl->setCurrentBlock("hidden_input");
         $tpl->setVariable("HID", $this->getId());
         $tpl->parseCurrentBlock();
         // init hidden input with selected value
         $tpl->setCurrentBlock("init_hidden_input");
         $tpl->setVariable("H2ID", $this->getId());
         $tpl->setVariable("HID_NAME", $this->form_mode["select_name"]);
         $tpl->setVariable("HID_VALUE", $this->getSelectedValue());
         $tpl->parseCurrentBlock();
     }
     // js section
     $tpl->setCurrentBlock("js_section");
     if ($this->getAccessKey() > 0) {
         include_once "./Services/Accessibility/classes/class.ilAccessKeyGUI.php";
         $tpl->setVariable("ACCKEY", ilAccessKeyGUI::getAttribute($this->getAccessKey()));
     }
     $cfg["trigger_event"] = $this->getTriggerEvent();
     $cfg["auto_hide"] = $this->getAutoHide();
     if ($this->getSelectCallback() != "") {
         $cfg["select_callback"] = $this->getSelectCallback();
     }
     $cfg["anchor_id"] = "ilAdvSelListAnchorElement_" . $this->getId();
     $cfg["asynch"] = $this->getAsynch() ? true : false;
     $cfg["asynch_url"] = $this->getAsynchUrl();
     $toggle = $this->getAdditionalToggleElement();
     if (is_array($toggle)) {
         $cfg["toggle_el"] = $toggle["el"];
         $cfg["toggle_class_on"] = $toggle["class_on"];
     }
     //echo "<br>".htmlentities($this->getAsynchUrl());
     include_once "./Services/JSON/classes/class.ilJsonUtil.php";
     $tpl->setVariable("TXT_SEL_TOP", $this->getListTitle());
     $tpl->setVariable("ID", $this->getId());
     $tpl->setVariable("CFG", ilJsonUtil::encode($cfg));
     //echo htmlentities(ilJsonUtil::encode($cfg));
     $tpl->setVariable("CLASS_SEL_TOP", $this->getSelectionHeaderClass());
     if ($this->getSelectionHeaderSpanClass() != "") {
         $tpl->setVariable("CLASS_SEL_TOP_SPAN", $this->getSelectionHeaderSpanClass());
     }
     // set the async url to an extra template variable
     // (needed for a mobile skin)
     $tpl->setVariable("ASYNC_URL", $this->getAsynchUrl());
     $tpl->parseCurrentBlock();
     // no js sections
     if (false) {
         switch ($this->mode) {
             // links mode
             case ilAdvancedSelectionListGUI::MODE_LINKS:
                 reset($items);
                 $cnt = 0;
                 foreach ($items as $item) {
                     $tpl->setCurrentBlock("no_js_link");
                     $tpl->setVariable("LINKS_CLASS", $this->links_mode["link_class"]);
                     $tpl->setVariable("LINKS_HREF", $item["link"]);
                     $tpl->setVariable("LINKS_TXT", $item["title"]);
                     $tpl->parseCurrentBlock();
                     $tpl->setCurrentBlock("no_js_section");
                     $tpl->parseCurrentBlock();
                 }
                 break;
             case ilAdvancedSelectionListGUI::MODE_FORM_SELECT:
                 reset($items);
                 $cnt = 0;
                 foreach ($items as $item) {
                     $tpl->setCurrentBlock("no_js_form_option");
                     $tpl->setVariable("FRM_OPTION_TXT", $item["title"]);
                     $tpl->setVariable("FRM_OPTION_VAL", $item["value"]);
                     if ($this->getSelectedValue() == $item["value"]) {
                         $tpl->setVariable("SELECTED", ' selected="selected" ');
                     }
                     $tpl->parseCurrentBlock();
                 }
                 if ($this->form_mode["include_form_tag"]) {
                     $tpl->setCurrentBlock("no_js_form_begin");
                     $tpl->setVariable("FRM_ID", $this->form_mode["form_id"]);
                     $tpl->setVariable("FRM_CLASS", $this->form_mode["form_class"]);
                     $tpl->setVariable("FRM_ACTION", $this->form_mode["form_action"]);
                     $tpl->setVariable("FRM_TARGET", $this->form_mode["form_target"]);
                     $tpl->parseCurrentBlock();
                     $tpl->touchBlock("no_js_form_end");
                 }
                 if ($this->form_mode["button_text"]) {
                     $tpl->setCurrentBlock("no_js_form_button");
                     $tpl->setVariable("FRM_BT_TXT", $this->form_mode["button_text"]);
                     $tpl->setVariable("FRM_BT_CLASS", $this->form_mode["button_class"]);
                     if ($this->form_mode["button_cmd"] != "") {
                         $tpl->setVariable("FRM_BT_CMD", 'name="cmd[' . $this->form_mode["button_cmd"] . ']"');
                     }
                     $tpl->parseCurrentBlock();
                 }
                 $tpl->setVariable("FRM_SELECT_NAME", $this->form_mode["select_name"]);
                 $tpl->setVariable("FRM_SELECT_CLASS", $this->form_mode["select_class"]);
                 if ($this->getAccessKey() > 0) {
                     include_once "./Services/Accessibility/classes/class.ilAccessKeyGUI.php";
                     $tpl->setVariable("ACCKEYNJS", ilAccessKeyGUI::getAttribute($this->getAccessKey()));
                 }
                 $tpl->setCurrentBlock("no_js_section");
                 $tpl->parseCurrentBlock();
                 break;
         }
     }
     return $tpl->get();
 }
Example #27
0
 /**
  * Initializes the preview and loads the needed javascripts and styles.
  */
 private static function initPreview()
 {
     if (self::$initialized) {
         return;
     }
     global $tpl, $lng, $ilCtrl;
     // jquery
     include_once "./Services/jQuery/classes/class.iljQueryUtil.php";
     iljQueryUtil::initjQuery();
     // load qtip
     include_once "./Services/UIComponent/Tooltip/classes/class.ilTooltipGUI.php";
     ilTooltipGUI::initLibrary();
     // needed scripts & styles
     $tpl->addJavaScript("./Services/Preview/js/jquery.mousewheel.js");
     $tpl->addJavaScript("./Services/Preview/js/ilPreview.js");
     $tpl->addCss(ilUtil::getStyleSheetLocation("filesystem", "preview.css", "Services/Preview"));
     // create loading template
     $tmpl = new ilTemplate("tpl.preview.html", true, true, "Services/Preview");
     $tmpl->setCurrentBlock("no_preview");
     $tmpl->setVariable("TXT_NO_PREVIEW", "%%0%%");
     $tmpl->parseCurrentBlock();
     $initialHtml = str_replace(array("\r\n", "\r"), "\n", $tmpl->get());
     $lines = explode("\n", $initialHtml);
     $new_lines = array();
     foreach ($lines as $i => $line) {
         if (!empty($line)) {
             $new_lines[] = trim($line);
         }
     }
     $initialHtml = implode($new_lines);
     // add default texts and values
     include_once "./Services/JSON/classes/class.ilJsonUtil.php";
     $tpl->addOnLoadCode("il.Preview.texts.preview = \"" . self::jsonSafeString($lng->txt("preview")) . "\";");
     $tpl->addOnLoadCode("il.Preview.texts.showPreview = \"" . self::jsonSafeString($lng->txt("preview_show")) . "\";");
     $tpl->addOnLoadCode("il.Preview.texts.close = \"" . self::jsonSafeString($lng->txt("close")) . "\";");
     $tpl->addOnLoadCode("il.Preview.previewSize = " . ilPreviewSettings::getImageSize() . ";");
     $tpl->addOnLoadCode("il.Preview.initialHtml = " . ilJsonUtil::encode($initialHtml) . ";");
     $tpl->addOnLoadCode("il.Preview.highlightClass = \"ilContainerListItemOuterHighlight\";");
     $tpl->addOnLoadCode("il.Preview.init();");
     self::$initialized = true;
 }
 function keywordAutocomplete()
 {
     include_once "./Services/MetaData/classes/class.ilMDKeyword.php";
     $res = ilMDKeyword::_getMatchingKeywords(ilUtil::stripSlashes($_GET["term"]), "blp", $this->getParentObjId());
     $result = array();
     $cnt = 0;
     foreach ($res as $r) {
         if ($cnt++ > 19) {
             continue;
         }
         $entry = new stdClass();
         $entry->value = $r;
         $entry->label = $r;
         $result[] = $entry;
     }
     include_once './Services/JSON/classes/class.ilJsonUtil.php';
     echo ilJsonUtil::encode($result);
     exit;
 }
 /**
  */
 protected function getMessages()
 {
     /**
      * @var $ilAccess ilAccessHandler
      * @var $ilUser   ilObjUser
      * @var $lng	  ilLanguage
      */
     global $ilAccess, $ilUser, $lng;
     $result = new stdClass();
     $result->ok = false;
     if (!(int) $_REQUEST['ref_id']) {
         echo ilJsonUtil::encode($result);
         exit;
     }
     /**
      * @var $object ilObjChatroom
      */
     $object = ilObjectFactory::getInstanceByRefId((int) $_REQUEST['ref_id'], false);
     if (!$object || !$ilAccess->checkAccess('read', '', $_REQUEST['ref_id'])) {
         ilObjUser::_writePref($ilUser->getId(), 'chatviewer_last_selected_room', 0);
         $result->errormsg = $lng->txt('msg_no_perm_read');
         echo ilJsonUtil::encode($result);
         exit;
     }
     require_once 'Modules/Chatroom/classes/class.ilChatroom.php';
     $room = ilChatroom::byObjectId($object->getId());
     $block = new ilChatroomBlock();
     $msg = $block->getMessages($room);
     $ilUser->setPref('chatviewer_last_selected_room', $object->getRefId());
     ilObjUser::_writePref($ilUser->getId(), 'chatviewer_last_selected_room', $object->getRefId());
     $result->messages = array_reverse($msg);
     $result->ok = true;
     include_once 'Services/JSON/classes/class.ilJsonUtil.php';
     echo ilJsonUtil::encode($result);
     exit;
 }
 /**
  * Get selection list HTML
  */
 public function getHTML($a_only_cmd_list_asynch = false)
 {
     $items = $this->getItems();
     // do not show list, if no item is in list
     if (count($items) == 0 && !$this->getAsynch() && $this->getGroupedList() == null) {
         return "";
     }
     /* bootstrap made this obsolete ?!
     		include_once("./Services/YUI/classes/class.ilYuiUtil.php");
     		ilYuiUtil::initOverlay();
     		$GLOBALS["tpl"]->addJavascript("./Services/UIComponent/Overlay/js/ilOverlay.js");					
     		*/
     $GLOBALS["tpl"]->addJavascript("./Services/UIComponent/AdvancedSelectionList/js/AdvancedSelectionList.js");
     $tpl = new ilTemplate("tpl.adv_selection_list.html", true, true, "Services/UIComponent/AdvancedSelectionList", "DEFAULT", false, true);
     reset($items);
     $cnt = 0;
     if ($this->getAsynch()) {
         $tpl->setCurrentBlock("asynch_request");
         $tpl->setVariable("IMG_LOADER", ilUtil::getImagePath("loader.svg"));
         $tpl->parseCurrentBlock();
     } else {
         if ($this->getGroupedList() != null) {
             $tpl->setVariable("GROUPED_LIST_HTML", $this->getGroupedList()->getHTML());
         } else {
             foreach ($items as $item) {
                 if (isset($item["ref_id"])) {
                     $sel_arr[$item["ref_id"]] = isset($item["title"]) ? $item["title"] : "";
                 }
                 $this->css_row = $this->css_row != "tblrow1_mo" ? "tblrow1_mo" : "tblrow2_mo";
                 if ($this->getUseImages()) {
                     if ($item["img"]) {
                         $tpl->setCurrentBlock("image");
                         $tpl->setVariable("IMG_ITEM", $item["img"]);
                         $tpl->setVariable("ALT_ITEM", $item["alt"]);
                         $tpl->parseCurrentBlock();
                     } else {
                         $tpl->touchBlock("no_image");
                     }
                 }
                 if ($this->getOnClickMode() == ilAdvancedSelectionListGUI::ON_ITEM_CLICK_HREF || $this->getItemLinkClass() != "") {
                     if ($item["frame"]) {
                         $tpl->setCurrentBlock("frame");
                         $tpl->setVariable("TARGET_ITEM", $item["frame"]);
                         $tpl->parseCurrentBlock();
                     }
                     if ($this->getItemLinkClass() != "") {
                         $tpl->setCurrentBlock("item_link_class");
                         $tpl->setVariable("ITEM_LINK_CLASS", $this->getItemLinkClass());
                         $tpl->parseCurrentBlock();
                     }
                     $tpl->setCurrentBlock("href_s");
                     $tpl->setVariable("HREF_ITEM", 'href="' . $item["link"] . '"');
                     $tpl->setVariable("ID_ITEM", $this->getId() . "_" . $item["value"]);
                     $tpl->parseCurrentBlock();
                     $tpl->touchBlock("href_e");
                 }
                 $tpl->setCurrentBlock("item");
                 if ($this->getOnClickMode() == ilAdvancedSelectionListGUI::ON_ITEM_CLICK_HREF) {
                     if ($item["prevent_background_click"]) {
                         $tpl->setVariable("ONCLICK_ITEM", '');
                     } else {
                         if ($item["onclick"] == "") {
                             $tpl->setVariable("ONCLICK_ITEM", 'onclick="' . "return il.AdvancedSelectionList.openTarget('" . $item["link"] . "','" . $item["frame"] . "');" . '"');
                         } else {
                             $tpl->setVariable("ONCLICK_ITEM", 'onclick="' . "return " . $item["onclick"] . ";" . '"');
                         }
                     }
                 } else {
                     if ($this->getOnClickMode() == ilAdvancedSelectionListGUI::ON_ITEM_CLICK_FORM_SUBMIT) {
                         $tpl->setVariable("ONCLICK_ITEM", 'onclick="return il.AdvancedSelectionList.submitForm(\'' . $this->getId() . '\'' . ", '" . $this->form_mode["select_name"] . "','" . $item["value"] . "'," . "'" . $this->on_click_form_id . "','" . $this->form_mode["button_cmd"] . "');\"");
                     } else {
                         if ($this->getOnClickMode() == ilAdvancedSelectionListGUI::ON_ITEM_CLICK_FORM_SELECT) {
                             $tpl->setVariable("ONCLICK_ITEM", 'onclick="return il.AdvancedSelectionList.selectForm(\'' . $this->getId() . '\'' . ", '" . $this->form_mode["select_name"] . "','" . $item["value"] . "'," . "'" . $item["title"] . "');\"");
                         } else {
                             if ($this->getOnClickMode() == ilAdvancedSelectionListGUI::ON_ITEM_CLICK_NOP) {
                                 $tpl->setVariable("ONCLICK_ITEM", 'onclick="il.AdvancedSelectionList.clickNop(\'' . $this->getId() . '\'' . ", '" . $this->form_mode["select_name"] . "','" . $item["value"] . "'," . "'" . $item["title"] . "');\"");
                             }
                         }
                     }
                 }
                 $tpl->setVariable("CSS_ROW", $this->css_row);
                 if ($item["html"] == "") {
                     $tpl->setVariable("TXT_ITEM", $item["title"]);
                 } else {
                     $tpl->setVariable("TXT_ITEM", $item["html"]);
                 }
                 $tpl->setVariable("ID_ITEM_TR", $this->getId() . "_" . $item["value"] . "_tr");
                 if ($item["ttip"] != "") {
                     include_once "./Services/UIComponent/Tooltip/classes/class.ilTooltipGUI.php";
                     ilTooltipGUI::addTooltip($this->getId() . "_" . $item["value"] . "_tr", $item["ttip"], "", $item["tt_my"], $item["tt_at"], $item["tt_use_htmlspecialchars"]);
                 }
                 $tpl->parseCurrentBlock();
                 // add item to js object
                 $tpl->setCurrentBlock("js_item");
                 $tpl->setVariable("IT_ID", $this->getId());
                 $tpl->setVariable("IT_HID_NAME", $this->form_mode["select_name"]);
                 $tpl->setVariable("IT_HID_VAL", $item["value"]);
                 $tpl->setVariable("IT_TITLE", str_replace("'", "\\'", $item["title"]));
                 $tpl->parseCurrentBlock();
             }
             // output hidden input, if click mode is form submission
             if ($this->getOnClickMode() == ilAdvancedSelectionListGUI::ON_ITEM_CLICK_FORM_SUBMIT) {
                 $tpl->setCurrentBlock("hidden_input");
                 $tpl->setVariable("HID", $this->getId());
                 $tpl->parseCurrentBlock();
             }
             // output hidden input and initialize
             if ($this->getOnClickMode() == ilAdvancedSelectionListGUI::ON_ITEM_CLICK_FORM_SELECT) {
                 $tpl->setCurrentBlock("hidden_input");
                 $tpl->setVariable("HID", $this->getId());
                 $tpl->parseCurrentBlock();
                 // init hidden input with selected value
                 $tpl->setCurrentBlock("init_hidden_input");
                 $tpl->setVariable("H2ID", $this->getId());
                 $tpl->setVariable("HID_NAME", $this->form_mode["select_name"]);
                 $tpl->setVariable("HID_VALUE", $this->getSelectedValue());
                 $tpl->parseCurrentBlock();
             }
         }
     }
     if ($a_only_cmd_list_asynch) {
         $tpl->touchBlock("cmd_table");
         return $tpl->get("cmd_table");
     }
     if ($this->getGroupedList() == null) {
         $tpl->setCurrentBlock("dd_content");
         if ($this->getPullRight()) {
             $tpl->setVariable("UL_CLASS", "dropdown-menu pull-right");
         } else {
             $tpl->setVariable("UL_CLASS", "dropdown-menu");
         }
         $tpl->setVariable("TABLE_ID", $this->getId());
         $tpl->parseCurrentBlock();
     }
     if ($this->getHeaderIcon() != ilAdvancedSelectionListGUI::NO_ICON) {
         $tpl->setCurrentBlock("top_img");
         switch ($this->getHeaderIcon()) {
             case ilAdvancedSelectionListGUI::ICON_CONFIG:
                 $tpl->setVariable("IMG_SPAN_STYLE", ilAdvancedSelectionListGUI::ICON_CONFIG);
                 break;
             case ilAdvancedSelectionListGUI::DOWN_ARROW_DARK:
             default:
                 $tpl->setVariable("IMG_SPAN_STYLE", ilAdvancedSelectionListGUI::ICON_ARROW);
                 break;
         }
         $tpl->parseCurrentBlock();
     }
     if ($this->getAsynch()) {
         $tpl->setCurrentBlock("asynch_bl");
         $tpl->setVariable("ASYNCH_URL", $this->getAsynchUrl());
         $tpl->setVariable("ASYNCH_ID", $this->getId());
         $tpl->setVariable("ASYNCH_TRIGGER_ID", $this->getId());
         $tpl->parseCurrentBlock();
     }
     // js section
     $tpl->setCurrentBlock("js_section");
     if ($this->getAccessKey() > 0) {
         include_once "./Services/Accessibility/classes/class.ilAccessKeyGUI.php";
         $tpl->setVariable("ACCKEY", ilAccessKeyGUI::getAttribute($this->getAccessKey()));
     }
     $cfg["trigger_event"] = $this->getTriggerEvent();
     $cfg["auto_hide"] = $this->getAutoHide();
     if ($this->getSelectCallback() != "") {
         $cfg["select_callback"] = $this->getSelectCallback();
     }
     $cfg["anchor_id"] = "ilAdvSelListAnchorElement_" . $this->getId();
     $cfg["asynch"] = $this->getAsynch() ? true : false;
     $cfg["asynch_url"] = $this->getAsynchUrl();
     $toggle = $this->getAdditionalToggleElement();
     if (is_array($toggle)) {
         $cfg["toggle_el"] = $toggle["el"];
         $cfg["toggle_class_on"] = $toggle["class_on"];
     }
     //echo "<br>".htmlentities($this->getAsynchUrl());
     include_once "./Services/JSON/classes/class.ilJsonUtil.php";
     $tpl->setVariable("CFG", ilJsonUtil::encode($cfg));
     //echo htmlentities(ilJsonUtil::encode($cfg));
     $tpl->setVariable("TXT_SEL_TOP", $this->getListTitle());
     $tpl->setVariable("ID", $this->getId());
     //$tpl->setVariable("CLASS_SEL_TOP", $this->getSelectionHeaderClass());
     switch ($this->getStyle()) {
         case self::STYLE_DEFAULT:
             $tpl->setVariable("BTN_CLASS", "btn btn-sm btn-default");
             $tpl->setVariable("TAG", "button");
             break;
         case self::STYLE_EMPH:
             $tpl->setVariable("BTN_CLASS", "btn btn-sm btn-primary");
             $tpl->setVariable("TAG", "button");
             break;
         case self::STYLE_LINK_BUTTON:
             $tpl->setVariable("BTN_CLASS", "btn btn-sm btn-link");
             $tpl->setVariable("TAG", "button");
             break;
         case self::STYLE_LINK:
             $tpl->setVariable("BTN_CLASS", "");
             $tpl->setVariable("TAG", "a");
             break;
     }
     if ($this->getSelectionHeaderSpanClass() != "") {
         $tpl->setVariable("CLASS_SEL_TOP_SPAN", $this->getSelectionHeaderSpanClass());
     }
     // set the async url to an extra template variable
     // (needed for a mobile skin)
     // $tpl->setVariable("ASYNC_URL", $this->getAsynchUrl());
     $tpl->parseCurrentBlock();
     return $tpl->get();
 }