public function getNavDivs()
 {
     global $CFG;
     $content = '';
     // Below code used for hiding subscription, courses and certifications tabs
     //echo $this->institution->getAppUrl();
     //echo $this->current_app->getUrl();
     $current_app_name = explode(".", $this->institution->getAppUrl());
     $current_app_short_name = $current_app_name[0];
     $current_app_short_name = str_replace("http://", "", $current_app_short_name);
     $current_app_short_name = str_replace("https://", "", $current_app_short_name);
     //echo $current_app_short_name."=".time();
     $this->ind_products_count = GcrInstitutionCatalogCoursesTable::getIndividualCoursesCount($current_app_short_name);
     $this->sub_products_count = GcrInstitutionCatalogCoursesTable::getSubscriptionCoursesCount($current_app_short_name);
     $this->cert_products_count = GcrInstitutionCatalogCoursesTable::getCertificationCoursesCount($current_app_short_name);
     if ($this->institution) {
         $content .= '<div id="main-nav">';
         $content .= '<ul>';
         $content .= '
         <li><a href="' . $this->institution->getAppUrl() . '" accesskey="h">Dashboard</a></li>
         <!-- <li><a href="' . $this->institution->getAppUrl() . 'view" accesskey="v">Pages</a></li> -->
         <li><a href="' . $this->institution->getAppUrl() . 'group/mygroups.php">Groups</a></li>';
         if ($this->sub_products_count > 0) {
             $content .= '<li><a href="' . $this->current_app->getUrl() . '/course/subscriptions">Subscriptions</a></li>';
         }
         if ($this->ind_products_count > 0) {
             $content .= '<li><a href="' . $this->current_app->getUrl() . '/course/view">Courses</a></li>';
         }
         if ($this->cert_products_count > 0) {
             $content .= '<li><a href="' . $this->current_app->getUrl() . '/course/certifications">Certifications</a></li>';
         }
         $content .= '</ul></div><div id="sub-nav"></div>';
     }
     return $content;
 }
 public function __construct($current_user = false)
 {
     global $CFG;
     $this->current_app = $CFG->current_app;
     $this->institution = false;
     if ($this->current_user = $current_user) {
         $this->institution = $current_user->getInstitution();
     }
     // Below code used for hiding subscription, courses and certifications tabs
     //echo $CFG->current_app->getUrl();
     $current_app_name = explode(".", $CFG->current_app->getUrl());
     $current_app_short_name = $current_app_name[0];
     $current_app_short_name = str_replace("http://", "", $current_app_short_name);
     $current_app_short_name = str_replace("https://", "", $current_app_short_name);
     //echo $current_app_short_name."=".time();
     $this->ind_products_count = GcrInstitutionCatalogCoursesTable::getIndividualCoursesCount($current_app_short_name);
     $this->sub_products_count = GcrInstitutionCatalogCoursesTable::getSubscriptionCoursesCount($current_app_short_name);
     $this->cert_products_count = GcrInstitutionCatalogCoursesTable::getCertificationCoursesCount($current_app_short_name);
 }
Пример #3
0
function mahara_navigation()
{
    global $CFG;
    $content = '';
    if ($CFG->current_app->hasPrivilege('Student')) {
        $mdl_user = $CFG->current_app->getCurrentUser();
        $institution = $mdl_user->getInstitution();
        if (!$institution) {
            $institution = $CFG->current_app->getInstitution();
        }
        $wwwroot = $institution->getAppUrl(false);
        $content = html_writer::start_tag('ul');
        //Home link
        $content .= html_writer::start_tag('li');
        $content .= html_writer::nonempty_tag('a', 'Dashboard', array('href' => "{$wwwroot}", 'accesskey' => 'h'));
        $content .= html_writer::end_tag('a');
        $content .= html_writer::end_tag('li');
        //Views link
        $content .= html_writer::start_tag('li');
        $content .= html_writer::nonempty_tag('a', 'Pages', array('href' => "{$wwwroot}/view", 'accesskey' => 'v'));
        $content .= html_writer::end_tag('a');
        $content .= html_writer::end_tag('li');
        //Groups link
        $content .= html_writer::start_tag('li');
        $content .= html_writer::nonempty_tag('a', 'Groups', array('href' => "{$wwwroot}/group/mygroups.php"));
        $content .= html_writer::end_tag('a');
        $content .= html_writer::end_tag('li');
        // Below code used for hiding subscription, courses and certifications tabs
        //echo $CFG->current_app->getUrl();
        $current_app_name = explode(".", $wwwroot);
        $current_app_short_name = $current_app_name[0];
        $current_app_short_name = str_replace("http://", "", $current_app_short_name);
        $current_app_short_name = str_replace("https://", "", $current_app_short_name);
        $current_app_short_name . "=" . time();
        $ind_products_count = GcrInstitutionCatalogCoursesTable::getIndividualCoursesCount($current_app_short_name);
        $sub_products_count = GcrInstitutionCatalogCoursesTable::getSubscriptionCoursesCount($current_app_short_name);
        $cert_products_count = GcrInstitutionCatalogCoursesTable::getCertificationCoursesCount($current_app_short_name);
        //Subscriptions link
        if ($sub_products_count > 0) {
            $content .= html_writer::start_tag('li');
            $content .= html_writer::nonempty_tag('a', 'Course Libraries', array('href' => $CFG->current_app->getUrl() . "/course/subscriptions"));
            $content .= html_writer::end_tag('a');
            $content .= html_writer::end_tag('li');
        }
        //Courses link
        if ($ind_products_count > 0) {
            $content .= html_writer::start_tag('li');
            $content .= html_writer::nonempty_tag('a', 'Single Courses', array('href' => $CFG->current_app->getUrl() . "/course/view"));
            $content .= html_writer::end_tag('a');
            $content .= html_writer::end_tag('li');
        }
        //Certifications link
        if ($cert_products_count > 0) {
            $content .= html_writer::start_tag('li');
            $content .= html_writer::nonempty_tag('a', 'Certifications', array('href' => $CFG->current_app->getUrl() . "/course/certifications"));
            $content .= html_writer::end_tag('a');
            $content .= html_writer::end_tag('li');
        }
        $role_manager = $CFG->current_app->getCurrentUser()->getRoleManager();
        if ($role_manager->HasPrivilege('GCUser')) {
            $content .= html_writer::start_tag('li');
            $content .= html_writer::nonempty_tag('a', 'Site Administration', array('href' => "{$wwwroot}/admin"));
            $content .= html_writer::end_tag('a');
            $content .= html_writer::end_tag('li');
        } else {
            if ($role_manager->HasPrivilege('EschoolAdmin')) {
                $content .= html_writer::start_tag('li');
                $content .= html_writer::nonempty_tag('a', 'Administration', array('href' => "{$wwwroot}/admin/users/search.php"));
                $content .= html_writer::end_tag('a');
                $content .= html_writer::end_tag('li');
            }
        }
        $content .= html_writer::end_tag('ul');
    }
    return $content;
}
 public function executeCronUpdateCoursesCount(sfWebRequest $request)
 {
     global $CFG;
     $CFG->current_app->requireMahara();
     $this->params = $request->getGetParameters();
     $platform_short_name = $CFG->current_app->getShortName();
     $product_type = isset($this->params['type']) ? $this->params['type'] : "";
     // gets all available schools
     $eschool_array = array();
     $catalog_courses_count = array();
     foreach ($CFG->current_app->getMnetEschools() as $eschool) {
         //if (GcrEschoolTable::authorizeEschoolAccess($eschool, true)) {
         $eschool_array[$eschool->getFullName()] = $eschool;
         //}
     }
     ksort($eschool_array);
     // gets catalog-wise courses count
     foreach ($eschool_array as $eschool) {
         $catalog_courses_count[$eschool->getShortName()] = $this->getHTMLCoursesCount($eschool->getShortName());
     }
     // gets all products list
     $all_products = GcrProductsTable::getAllProducts($platform_short_name, $product_type);
     $all_products_details = array();
     foreach ($all_products as $product) {
         $all_products_details[$product->getShortName()]["id"] = $product->getId();
         $all_products_details[$product->getShortName()]["product_type_id"] = $product->getProductTypeId();
         $all_products_details[$product->getShortName()]["short_name"] = $product->getShortName();
         $all_products_details[$product->getShortName()]["institution_short_name"] = $product->getInstitutionShortName();
         $all_products_details[$product->getShortName()]["catalog_short_name"] = $product->getCatalogShortName();
         $all_products_details[$product->getShortName()]["platform_short_name"] = $product->getPlatformShortName();
         if ($product->getProductTypeId() == 2 || $product->getProductTypeId() == 3) {
             $is_exist = GcrInstitutionCatalogCoursesTable::checkIsExist($product->getInstitutionShortName(), $product->getCatalogShortName(), $product->getPlatformShortName());
             $ctlg_crses_count = isset($catalog_courses_count[$product->getCatalogShortName()]) ? $catalog_courses_count[$product->getCatalogShortName()] : 0;
             if ($is_exist == 0) {
                 $cron_obj = new GcrInstitutionCatalogCourses();
                 $cron_obj->setPlatformShortName($product->getPlatformShortName());
                 $cron_obj->setInstitutionShortName($product->getInstitutionShortName());
                 $cron_obj->setCatalogShortName($product->getCatalogShortName());
                 $cron_obj->setProductTypeId($product->getProductTypeId());
                 $cron_obj->setCoursesCount($ctlg_crses_count);
                 $cron_obj->save();
             } else {
                 Doctrine_Query::create()->update('GcrInstitutionCatalogCourses')->set('courses_count', '?', $ctlg_crses_count)->where('institution_short_name = ?', $product->getInstitutionShortName())->andWhere('platform_short_name = ?', $product->getPlatformShortName())->andWhere('catalog_short_name = ?', $product->getCatalogShortName())->andWhere('product_type_id = ?', $product->getProductTypeId())->execute();
             }
         } else {
             if ($product->getProductTypeId() == 1) {
                 $institution_name = $product->getInstitutionShortName();
                 $mhr_institution_obj = $CFG->current_app->selectFromMhrTable('institution', 'name', $institution_name, true);
                 if ($mhr_institution_obj) {
                     $mhr_institution = new GcrMhrInstitution($mhr_institution_obj, $CFG->current_app);
                     $current_eschools = array();
                     $eschools = $mhr_institution->getEschools();
                     if ($eschools) {
                         foreach ($eschools as $eschool) {
                             $current_eschools[$eschool->getShortName()] = $eschool->getFullName();
                         }
                     }
                     asort($current_eschools);
                     foreach ($current_eschools as $current_eschool_key => $current_eschool_val) {
                         if (stripos(strtolower($current_eschool_val), "(*)") === false && stripos(strtolower($current_eschool_val), "(\$)") === false) {
                             $params = array();
                             $params["start_index"] = 0;
                             $params["mode"] = "Eschool";
                             $params["mode_id"] = $current_eschool_key;
                             $this->course_list = new GcrCourseList($params, $CFG->current_app);
                             $catalog_courses_count[$current_eschool_key] = $this->course_list->getCoursesCount();
                             $is_exist = GcrInstitutionCatalogCoursesTable::checkIsExist($product->getInstitutionShortName(), $current_eschool_key, $product->getPlatformShortName());
                             $ctlg_crses_count = isset($catalog_courses_count[$current_eschool_key]) ? $catalog_courses_count[$current_eschool_key] : 0;
                             if ($is_exist == 0) {
                                 $cron_obj = new GcrInstitutionCatalogCourses();
                                 $cron_obj->setPlatformShortName($product->getPlatformShortName());
                                 $cron_obj->setInstitutionShortName($product->getInstitutionShortName());
                                 $cron_obj->setCatalogShortName($current_eschool_key);
                                 $cron_obj->setProductTypeId($product->getProductTypeId());
                                 $cron_obj->setCoursesCount($ctlg_crses_count);
                                 $cron_obj->save();
                             } else {
                                 Doctrine_Query::create()->update('GcrInstitutionCatalogCourses')->set('courses_count', '?', $ctlg_crses_count)->where('institution_short_name = ?', $product->getInstitutionShortName())->andWhere('platform_short_name = ?', $product->getPlatformShortName())->andWhere('catalog_short_name = ?', $current_eschool_key)->andWhere('product_type_id = ?', $product->getProductTypeId())->execute();
                             }
                         }
                     }
                 }
             }
         }
     }
     /* 		print "<pre>";
     		print_r($catalog_courses_count);
     		//print_r($all_products_details);
     		print "</pre>"; */
     echo "<br>Completed<br>";
     exit;
 }
Пример #5
0
/**
 * This function creates a Smarty object and sets it up for use within our
 * podclass app, setting up some variables.
 *
 * WARNING: If you are using pieforms, set them up BEFORE calling this function.
 *
 * The variables that it sets up are:
 *
 * - WWWROOT: The base url for the Mahara system
 * - USER: The user object
 * - JAVASCRIPT: A list of javascript files to include in the header.  This
 *   list is passed into this function (see below).
 * - HEADERS: An array of any further headers to set.  Each header is just
 *   straight HTML (see below).
 * - PUBLIC: Set true if this page is a public page
 * - MAINNAV: Array defining the main navigation
 *
 * @param $javascript A list of javascript includes.  Each include should be just
 *                    the name of a file, and reside in js/{filename}
 * @param $headers    A list of additional headers.  These are to be specified as
 *                    actual HTML.
 * @param $strings    A list of language strings required by the javascript code.
 * @return Smarty
 */
function smarty($javascript = array(), $headers = array(), $pagestrings = array(), $extraconfig = array())
{
    global $USER, $SESSION, $THEME, $HEADDATA, $langselectform;
    if (!is_array($headers)) {
        $headers = array();
    }
    if (!is_array($pagestrings)) {
        $pagestrings = array();
    }
    if (!is_array($extraconfig)) {
        $extraconfig = array();
    }
    $sideblocks = array();
    // Some things like die_info() will try and create a smarty() call when we are already in one, which causes
    // language_select_form() to throw headdata error as it is called twice.
    if (!isset($langselectform)) {
        $langselectform = language_select_form();
    }
    $smarty = smarty_core();
    $wwwroot = get_config('wwwroot');
    // NOTE: not using jswwwroot - it seems to wreck image paths if you
    // drag them around the wysiwyg editor
    $jswwwroot = json_encode($wwwroot);
    // Workaround for $cfg->cleanurlusersubdomains.
    // When cleanurlusersubdomains is on, ajax requests might come from somewhere other than
    // the wwwroot.  To avoid cross-domain requests, set a js variable when this page is on a
    // different subdomain, and let the ajax wrapper function sendjsonrequest rewrite its url
    // if necessary.
    if (get_config('cleanurls') && get_config('cleanurlusersubdomains')) {
        if ($requesthost = get_requested_host_name()) {
            $wwwrootparts = parse_url($wwwroot);
            if ($wwwrootparts['host'] != $requesthost) {
                $fakewwwroot = $wwwrootparts['scheme'] . '://' . $requesthost . '/';
                $headers[] = '<script type="text/javascript">var fakewwwroot = ' . json_encode($fakewwwroot) . ';</script>';
            }
        }
    }
    $theme_list = array();
    if (function_exists('pieform_get_headdata')) {
        $headers = array_merge($headers, pieform_get_headdata());
        if (!defined('PIEFORM_GOT_HEADDATA')) {
            define('PIEFORM_GOT_HEADDATA', 1);
        }
    }
    // Define the stylesheets array early so that javascript modules can add extras
    $stylesheets = array();
    // Insert the appropriate javascript tags
    $javascript_array = array();
    $jsroot = $wwwroot . 'js/';
    $langdirection = get_string('thisdirection', 'langconfig');
    // Make jQuery accessible with $j (Mochikit has $)
    $javascript_array[] = $jsroot . 'jquery/jquery.js';
    $javascript_array[] = $jsroot . 'jquery/deprecated_jquery.js';
    $headers[] = '<script type="text/javascript">$j=jQuery;</script>';
    // TinyMCE must be included first for some reason we're not sure about
    //
    // Note: we do not display tinyMCE for mobile devices
    // as it doesn't work on some of them and can
    // disable the editing of a textarea field
    if ($SESSION->get('handheld_device') == false) {
        $checkarray = array(&$javascript, &$headers);
        $found_tinymce = false;
        foreach ($checkarray as &$check) {
            if (($key = array_search('tinymce', $check)) !== false || ($key = array_search('tinytinymce', $check)) !== false) {
                if (!$found_tinymce) {
                    $found_tinymce = $check[$key];
                    $javascript_array[] = $jsroot . 'tinymce/tinymce.js';
                    $stylesheets = array_merge($stylesheets, array_reverse(array_values($THEME->get_url('style/tinymceskin.css', true))));
                    $content_css = json_encode($THEME->get_url('style/tinymce.css'));
                    $language = current_language();
                    $language = substr($language, 0, substr_count($language, '_') > 0 ? 5 : 2);
                    if ($language != 'en' && !file_exists(get_config('docroot') . 'js/tinymce/langs/' . $language . '.js')) {
                        // In case the language file exists as a string with both lower and upper case, eg fr_FR we test for this
                        $language = substr($language, 0, 2) . '_' . strtoupper(substr($language, 0, 2));
                        if (!file_exists(get_config('docroot') . 'js/tinymce/langs/' . $language . '.js')) {
                            // In case we fail to find a language of 5 chars, eg pt_BR (Portugese, Brazil) we try the 'parent' pt (Portugese)
                            $language = substr($language, 0, 2);
                            if ($language != 'en' && !file_exists(get_config('docroot') . 'js/tinymce/langs/' . $language . '.js')) {
                                $language = 'en';
                            }
                        }
                    }
                    $extrasetup = isset($extraconfig['tinymcesetup']) ? $extraconfig['tinymcesetup'] : '';
                    $extramceconfig = isset($extraconfig['tinymceconfig']) ? $extraconfig['tinymceconfig'] : '';
                    // Check whether to make the spellchecker available
                    $aspellpath = get_config('pathtoaspell');
                    if ($aspellpath && file_exists($aspellpath) && is_executable($aspellpath)) {
                        $spellchecker = ',spellchecker';
                        $spellchecker_config = "gecko_spellcheck : false, spellchecker_rpc_url : \"{$jsroot}tinymce/plugins/spellchecker/rpc.php\",";
                    } else {
                        $spellchecker = '';
                        $spellchecker_config = 'gecko_spellcheck : true,';
                    }
                    $toolbar = array(null, '"toolbar_toggle | formatselect | bold italic | bullist numlist | link unlink | image media | undo redo"', '"underline strikethrough subscript superscript | alignleft aligncenter alignright alignjustify | outdent indent | forecolor backcolor | ltr rtl | fullscreen"', '"fontselect | fontsizeselect | emoticons nonbreaking charmap | spellchecker | table | removeformat pastetext | code"');
                    // For right-to-left langs, reverse button order & align controls right.
                    $tinymce_langdir = $langdirection == 'rtl' ? 'rtl' : 'ltr';
                    $toolbar_align = 'left';
                    // Language strings required for TinyMCE
                    $pagestrings['mahara'] = isset($pagestrings['mahara']) ? $pagestrings['mahara'] : array();
                    $pagestrings['mahara'][] = 'attachedimage';
                    if ($check[$key] == 'tinymce') {
                        $tinymceconfig = <<<EOF
    theme: "modern",
    plugins: "tooltoggle,textcolor,link,image,table,emoticons,spellchecker,paste,code,fullscreen,directionality,searchreplace,nonbreaking,charmap,media",
    toolbar1: {$toolbar[1]},
    toolbar2: {$toolbar[2]},
    toolbar3: {$toolbar[3]},
    menubar: false,
    fix_list_elements: true,
    image_advtab: true,
    {$spellchecker_config}
EOF;
                    } else {
                        $tinymceconfig = <<<EOF
    selector: "textarea.tinywysiwyg",
    theme: "modern",
    plugins: "fullscreen,autoresize,media",               
    toolbar: {$toolbar[0]},
EOF;
                    }
                    $headers[] = <<<EOF
<script type="text/javascript">
tinyMCE.init({
    {$tinymceconfig}
    schema: 'html4',
    extended_valid_elements : "object[width|height|classid|codebase],param[name|value],embed[src|type|width|height|flashvars|wmode],script[src,type,language],+ul[id|type|compact],iframe[src|width|height|align|title|class|type|frameborder|allowfullscreen]",
    urlconverter_callback : "custom_urlconvert",
    language: '{$language}',
    directionality: "{$tinymce_langdir}",
    content_css : {$content_css},
    remove_script_host: false,
    relative_urls: false,
    {$extramceconfig}
    setup: function(ed) {
        ed.on('init', function(ed) {
            if (typeof(editor_to_focus) == 'string' && ed.editorId == editor_to_focus) {
                ed.focus();
            }
        });
        ed.on('LoadContent', function(e) {
            // Hide all the 2nd/3rd row menu buttons
            jQuery('.mce-toolbar.mce-first').siblings().toggleClass('hidden');
});
        {$extrasetup}
    }
});    
function custom_urlconvert (u, n, e) {
  // Don't convert the url on the skype status buttons.
  if (u.indexOf('skype:') == 0) {
      return u;
  }
  var t = tinyMCE.activeEditor, s = t.settings;

  // Don't convert link href since thats the CSS files that gets loaded into the editor also skip local file URLs
  if (!s.convert_urls || (e && e.nodeName == 'LINK') || u.indexOf('file:') === 0)
      return u;

  // Convert to relative
  if (s.relative_urls)
      return t.documentBaseURI.toRelative(u);

  // Convert to absolute
  u = t.documentBaseURI.toAbsolute(u, s.remove_script_host);

  return u;
}
</script>

EOF;
                    unset($check[$key]);
                } else {
                    if ($check[$key] != $found_tinymce) {
                        log_warn('Two differently configured tinyMCE instances have been asked for on this page! This is not possible');
                    }
                    unset($check[$key]);
                }
            }
            // If any page adds jquery explicitly, remove it from the list
            if (($key = array_search('jquery', $check)) !== false) {
                unset($check[$key]);
            }
        }
    } else {
        if (($key = array_search('tinymce', $javascript)) !== false || ($key = array_search('tinytinymce', $javascript)) !== false) {
            unset($javascript[$key]);
        }
        if (($key = array_search('tinymce', $headers)) !== false || ($key = array_search('tinytinymce', $headers)) !== false) {
            unset($headers[$key]);
        }
    }
    if (get_config('developermode') & DEVMODE_UNPACKEDJS) {
        $javascript_array[] = $jsroot . 'MochiKit/MochiKit.js';
        $javascript_array[] = $jsroot . 'MochiKit/Position.js';
        $javascript_array[] = $jsroot . 'MochiKit/Color.js';
        $javascript_array[] = $jsroot . 'MochiKit/Visual.js';
        $javascript_array[] = $jsroot . 'MochiKit/DragAndDrop.js';
        $javascript_array[] = $jsroot . 'MochiKit/Format.js';
    } else {
        $javascript_array[] = $jsroot . 'MochiKit/Packed.js';
    }
    $javascript_array[] = $jsroot . 'keyboardNavigation.js';
    $strings = array();
    foreach ($pagestrings as $k => $v) {
        if (is_array($v)) {
            foreach ($v as $tag) {
                $strings[$tag] = get_raw_string($tag, $k);
            }
        } else {
            $strings[$k] = get_raw_string($k, $v);
        }
    }
    $jsstrings = jsstrings();
    $themepaths = themepaths();
    foreach ($javascript as $jsfile) {
        // For now, if there's no path in the js file, assume it's in
        // $jsroot and append '.js' to the name.  Later we may want to
        // ensure all smarty() calls include the full path to the js
        // file, with the proper extension.
        if (strpos($jsfile, '/') === false) {
            $javascript_array[] = $jsroot . $jsfile . '.js';
            if (isset($jsstrings[$jsfile])) {
                foreach ($jsstrings[$jsfile] as $section => $tags) {
                    foreach ($tags as $tag) {
                        $strings[$tag] = get_raw_string($tag, $section);
                    }
                }
            }
            if (isset($themepaths[$jsfile])) {
                foreach ($themepaths[$jsfile] as $themepath) {
                    $theme_list[$themepath] = $THEME->get_url($themepath);
                }
            }
        } else {
            if (stripos($jsfile, 'http://') === false && stripos($jsfile, 'https://') === false) {
                // A local .js file with a fully specified path
                $javascript_array[] = $wwwroot . $jsfile;
                // If $jsfile is from a plugin (i.e. plugintype/pluginname/js/foo.js)
                // Then get js strings from static function jsstrings in plugintype/pluginname/lib.php
                $bits = explode('/', $jsfile);
                if (count($bits) == 4) {
                    safe_require($bits[0], $bits[1]);
                    $pluginclass = generate_class_name($bits[0], $bits[1]);
                    $name = substr($bits[3], 0, strpos($bits[3], '.js'));
                    if (is_callable(array($pluginclass, 'jsstrings'))) {
                        $tempstrings = call_static_method($pluginclass, 'jsstrings', $name);
                        foreach ($tempstrings as $section => $tags) {
                            foreach ($tags as $tag) {
                                $strings[$tag] = get_raw_string($tag, $section);
                            }
                        }
                    }
                    if (is_callable(array($pluginclass, 'jshelp'))) {
                        $tempstrings = call_static_method($pluginclass, 'jshelp', $name);
                        foreach ($tempstrings as $section => $tags) {
                            foreach ($tags as $tag) {
                                $strings[$tag . '.help'] = get_help_icon($bits[0], $bits[1], null, null, null, $tag);
                            }
                        }
                    }
                    if (is_callable(array($pluginclass, 'themepaths'))) {
                        $tmpthemepaths = call_static_method($pluginclass, 'themepaths', $name);
                        foreach ($tmpthemepaths as $themepath) {
                            $theme_list[$themepath] = $THEME->get_url($themepath);
                        }
                    }
                }
            } else {
                // A remote .js file
                $javascript_array[] = $jsfile;
            }
        }
    }
    $javascript_array[] = $jsroot . 'mahara.js';
    $javascript_array[] = $jsroot . 'formchangechecker.js';
    if (get_config('developermode') & DEVMODE_DEBUGJS) {
        $javascript_array[] = $jsroot . 'debug.js';
    }
    foreach ($jsstrings['mahara'] as $section => $tags) {
        foreach ($tags as $tag) {
            $strings[$tag] = get_raw_string($tag, $section);
        }
    }
    if (isset($extraconfig['themepaths']) && is_array($extraconfig['themepaths'])) {
        foreach ($extraconfig['themepaths'] as $themepath) {
            $theme_list[$themepath] = $THEME->get_url($themepath);
        }
    }
    $stringjs = '<script type="text/javascript">';
    $stringjs .= 'var strings = ' . json_encode($strings) . ';';
    $stringjs .= "\nfunction plural(n) { return " . get_raw_string('pluralrule', 'langconfig') . "; }\n";
    $stringjs .= '</script>';
    // stylesheet set up - if we're in a plugin also get its stylesheet
    $stylesheets = array_merge($stylesheets, array_reverse(array_values($THEME->get_url('style/style.css', true))));
    if (defined('SECTION_PLUGINTYPE') && defined('SECTION_PLUGINNAME') && SECTION_PLUGINTYPE != 'core') {
        if ($pluginsheets = $THEME->get_url('style/style.css', true, SECTION_PLUGINTYPE . '/' . SECTION_PLUGINNAME)) {
            $stylesheets = array_merge($stylesheets, array_reverse($pluginsheets));
        }
    }
    if ($adminsection = in_admin_section()) {
        if ($adminsheets = $THEME->get_url('style/admin.css', true)) {
            $stylesheets = array_merge($stylesheets, array_reverse($adminsheets));
        }
    }
    if (get_config('developermode') & DEVMODE_DEBUGCSS) {
        $stylesheets[] = get_config('wwwroot') . 'theme/debug.css';
    }
    // look for extra stylesheets
    if (isset($extraconfig['stylesheets']) && is_array($extraconfig['stylesheets'])) {
        foreach ($extraconfig['stylesheets'] as $extrasheet) {
            if ($sheets = $THEME->get_url($extrasheet, true)) {
                $stylesheets = array_merge($stylesheets, array_reverse(array_values($sheets)));
            }
        }
    }
    if ($sheets = $THEME->additional_stylesheets()) {
        $stylesheets = array_merge($stylesheets, $sheets);
    }
    // Give the skin a chance to affect the page
    if (!empty($extraconfig['skin'])) {
        require_once get_config('docroot') . '/lib/skin.php';
        $skinobj = new Skin($extraconfig['skin']['skinid']);
        $viewid = isset($extraconfig['skin']['viewid']) ? $extraconfig['skin']['viewid'] : null;
        $stylesheets = array_merge($stylesheets, $skinobj->get_stylesheets($viewid));
    }
    // Allow us to set the HTML lang attribute
    $smarty->assign('LANGUAGE', substr(current_language(), 0, 2));
    // Include rtl.css for right-to-left langs
    if ($langdirection == 'rtl') {
        $smarty->assign('LANGDIRECTION', 'rtl');
        if ($rtlsheets = $THEME->get_url('style/rtl.css', true)) {
            $stylesheets = array_merge($stylesheets, array_reverse($rtlsheets));
        }
    }
    $smarty->assign('STRINGJS', $stringjs);
    $stylesheets = append_version_number($stylesheets);
    $smarty->assign('STYLESHEETLIST', $stylesheets);
    if (!empty($theme_list)) {
        // this gets assigned in smarty_core, but do it again here if it's changed locally
        $smarty->assign('THEMELIST', json_encode(array_merge((array) json_decode($smarty->get_template_vars('THEMELIST')), $theme_list)));
    }
    $dropdownmenu = get_config('dropdownmenu');
    // disable drop-downs if overridden at institution level
    $sitethemeprefs = get_config('sitethemeprefs');
    $institutions = $USER->institutions;
    if (!empty($institutions)) {
        foreach ($institutions as $i) {
            if (!empty($sitethemeprefs)) {
                if (!empty($USER->accountprefs['theme']) && $USER->accountprefs['theme'] == $THEME->basename . '/' . $i->institution) {
                    $dropdownmenu = $i->dropdownmenu;
                }
            } else {
                if (!empty($USER->accountprefs['theme']) && $USER->accountprefs['theme'] == $THEME->basename . '/' . $i->institution || empty($USER->accountprefs) && $i->theme == $THEME->basename && $USER->institutiontheme->institutionname == $i->institution) {
                    $dropdownmenu = $i->dropdownmenu;
                }
            }
        }
    }
    // and/or disable drop-downs if a handheld device detected
    $dropdownmenu = $SESSION->get('handheld_device') ? false : $dropdownmenu;
    if ($dropdownmenu) {
        $smarty->assign('DROPDOWNMENU', $dropdownmenu);
        $javascript_array[] = $jsroot . 'dropdown-nav.js';
    }
    $smarty->assign('MOBILE', $SESSION->get('mobile'));
    $smarty->assign('HANDHELD_DEVICE', $SESSION->get('handheld_device'));
    $sitename = get_config('sitename');
    if (!$sitename) {
        $sitename = 'Mahara';
    }
    $smarty->assign('sitename', $sitename);
    $sitelogo = $THEME->header_logo();
    $sitelogo = append_version_number($sitelogo);
    $smarty->assign('sitelogo', $sitelogo);
    $smarty->assign('sitelogo4facebook', $THEME->facebook_logo());
    $smarty->assign('sitedescription4facebook', get_string('facebookdescription', 'mahara'));
    if (defined('TITLE')) {
        $smarty->assign('PAGETITLE', TITLE . ' - ' . $sitename);
        $smarty->assign('heading', TITLE);
    } else {
        $smarty->assign('PAGETITLE', $sitename);
    }
    $smarty->assign('PRODUCTIONMODE', get_config('productionmode'));
    if (function_exists('local_header_top_content')) {
        $sitetop = (isset($sitetop) ? $sitetop : '') . local_header_top_content();
    }
    if (isset($sitetop)) {
        $smarty->assign('SITETOP', $sitetop);
    }
    if (defined('PUBLIC')) {
        $smarty->assign('PUBLIC', true);
    }
    if (defined('ADMIN')) {
        $smarty->assign('ADMIN', true);
    }
    if (defined('INSTITUTIONALADMIN')) {
        $smarty->assign('INSTITUTIONALADMIN', true);
    }
    if (defined('STAFF')) {
        $smarty->assign('STAFF', true);
    }
    if (defined('INSTITUTIONALSTAFF')) {
        $smarty->assign('INSTITUTIONALSTAFF', true);
    }
    // Below code used for hiding subscription, courses and certifications tabs
    $current_app_name = explode(".", get_requested_host_name());
    $current_app_short_name = $current_app_name[0];
    //echo $current_app_short_name."=".time();
    $ind_products_count = GcrInstitutionCatalogCoursesTable::getIndividualCoursesCount($current_app_short_name);
    $sub_products_count = GcrInstitutionCatalogCoursesTable::getSubscriptionCoursesCount($current_app_short_name);
    $cert_products_count = GcrInstitutionCatalogCoursesTable::getCertificationCoursesCount($current_app_short_name);
    /* echo "<br>";
    	echo $ind_products_count;
    	echo "<br>";
    	echo $sub_products_count;
    	echo "<br>";
    	echo $cert_products_count;
    	echo "<br>";
    	exit; */
    if ($sub_products_count > 0) {
        $smarty->assign('SUBSCRIPTIONS_EXIST', true);
    }
    if ($ind_products_count > 0) {
        $smarty->assign('COURSES_EXIST', true);
    }
    if ($cert_products_count > 0) {
        $smarty->assign('CERTIFICATIONS_EXIST', true);
    }
    $smarty->assign('LOGGEDIN', $USER->is_logged_in());
    $publicsearchallowed = false;
    $searchplugin = get_config('searchplugin');
    if ($searchplugin) {
        safe_require('search', $searchplugin);
        $publicsearchallowed = call_static_method(generate_class_name('search', $searchplugin), 'publicform_allowed') && get_config('publicsearchallowed');
    }
    $smarty->assign('publicsearchallowed', $publicsearchallowed);
    if ($USER->is_logged_in()) {
        global $SELECTEDSUBNAV;
        // It's evil, but rightnav & mainnav stuff are now in different templates.
        $smarty->assign('MAINNAV', main_nav());
        $mainnavsubnav = $SELECTEDSUBNAV;
        $smarty->assign('RIGHTNAV', right_nav());
        if (!$mainnavsubnav && $dropdownmenu) {
            // In drop-down navigation, the submenu is only usable if its parent is one of the top-level menu
            // items.  But if the submenu comes from something in right_nav (settings), it's unreachable.
            // Turning the submenu into SUBPAGENAV group-style tabs makes it usable.
            $smarty->assign('SUBPAGENAV', $SELECTEDSUBNAV);
        } else {
            $smarty->assign('SELECTEDSUBNAV', $SELECTEDSUBNAV);
        }
    } else {
        $smarty->assign('languageform', $langselectform);
    }
    $smarty->assign('FOOTERMENU', footer_menu());
    $smarty->assign_by_ref('USER', $USER);
    $smarty->assign('SESSKEY', $USER->get('sesskey'));
    $smarty->assign('CC_ENABLED', get_config('cookieconsent_enabled'));
    $javascript_array = append_version_number($javascript_array);
    $smarty->assign_by_ref('JAVASCRIPT', $javascript_array);
    $smarty->assign('RELEASE', get_config('release'));
    $smarty->assign('SERIES', get_config('series'));
    $smarty->assign('CACHEVERSION', get_config('cacheversion'));
    $siteclosedforupgrade = get_config('siteclosed');
    if ($siteclosedforupgrade && get_config('disablelogin')) {
        $smarty->assign('SITECLOSED', 'logindisabled');
    } else {
        if ($siteclosedforupgrade || get_config('siteclosedbyadmin')) {
            $smarty->assign('SITECLOSED', 'loginallowed');
        }
    }
    if (!isset($extraconfig['pagehelp']) || $extraconfig['pagehelp'] !== false and $help = has_page_help()) {
        $smarty->assign('PAGEHELPNAME', $help[0]);
        $smarty->assign('PAGEHELPICON', $help[1]);
    }
    if (defined('GROUP')) {
        require_once 'group.php';
        if ($group = group_current_group()) {
            $smarty->assign('GROUP', $group);
            if (!defined('NOGROUPMENU')) {
                $smarty->assign('SUBPAGENAV', group_get_menu_tabs());
                $smarty->assign('PAGEHEADING', $group->name);
            }
        }
    }
    // ---------- sideblock stuff ----------
    $sidebars = !isset($extraconfig['sidebars']) || $extraconfig['sidebars'] !== false;
    if ($sidebars && !defined('INSTALLER') && (!defined('MENUITEM') || substr(MENUITEM, 0, 5) != 'admin')) {
        if (get_config('installed') && !$adminsection) {
            $data = site_menu();
            if (!empty($data)) {
                $smarty->assign('SITEMENU', site_menu());
                $sideblocks[] = array('name' => 'linksandresources', 'weight' => 10, 'data' => $data);
            }
        }
        if ($USER->is_logged_in() && defined('MENUITEM') && (substr(MENUITEM, 0, 11) == 'myportfolio' || substr(MENUITEM, 0, 7) == 'content')) {
            if (get_config('showselfsearchsideblock')) {
                $sideblocks[] = array('name' => 'selfsearch', 'weight' => 0, 'data' => array());
            }
            if (get_config('showtagssideblock')) {
                $sideblocks[] = array('name' => 'tags', 'id' => 'sb-tags', 'weight' => 0, 'data' => tags_sideblock());
            }
        }
        if ($USER->is_logged_in() && !$adminsection) {
            $sideblocks[] = array('name' => 'profile', 'id' => 'sb-profile', 'weight' => -20, 'data' => profile_sideblock());
            $showusers = 2;
            $institutions = $USER->institutions;
            if (!empty($institutions)) {
                $showusers = 0;
                foreach ($institutions as $i) {
                    if ($i->showonlineusers == 2) {
                        $showusers = 2;
                        break;
                    }
                    if ($i->showonlineusers == 1) {
                        $showusers = 1;
                    }
                }
            }
            if (get_config('showonlineuserssideblock') && $showusers > 0) {
                $sideblocks[] = array('name' => 'onlineusers', 'id' => 'sb-onlineusers', 'weight' => -10, 'data' => onlineusers_sideblock());
            }
            if (get_config('showprogressbar') && $USER->get_account_preference('showprogressbar')) {
                $sideblocks[] = array('name' => 'progressbar', 'id' => 'sb-progressbar', 'weight' => -8, 'data' => progressbar_sideblock());
            }
        }
        if ($USER->is_logged_in() && $adminsection && defined('SECTION_PAGE') && SECTION_PAGE == 'progressbar') {
            $sideblocks[] = array('name' => 'progressbar', 'id' => 'sb-progressbar', 'weight' => -8, 'data' => progressbar_sideblock(true));
        }
        if (!$USER->is_logged_in() && !(get_config('siteclosed') && get_config('disablelogin'))) {
            $sideblocks[] = array('name' => 'login', 'weight' => -10, 'id' => 'sb-loginbox', 'data' => array('loginform' => auth_generate_login_form()));
        }
        if (get_config('enablenetworking')) {
            require_once get_config('docroot') . 'api/xmlrpc/lib.php';
            if ($USER->is_logged_in() && ($ssopeers = get_service_providers($USER->authinstance))) {
                $sideblocks[] = array('name' => 'ssopeers', 'weight' => 1, 'data' => $ssopeers);
            }
        }
        if (isset($extraconfig['sideblocks']) && is_array($extraconfig['sideblocks'])) {
            foreach ($extraconfig['sideblocks'] as $sideblock) {
                $sideblocks[] = $sideblock;
            }
        }
        // local_sideblocks_update allows sites to customise the sideblocks by munging the $sideblocks array.
        if (function_exists('local_sideblocks_update')) {
            local_sideblocks_update($sideblocks);
        }
        usort($sideblocks, create_function('$a,$b', 'if ($a["weight"] == $b["weight"]) return 0; return ($a["weight"] < $b["weight"]) ? -1 : 1;'));
        // Place all sideblocks on the right. If this structure is munged
        // appropriately, you can put blocks on the left. In future versions of
        // Mahara, we'll make it easy to do this.
        $sidebars = $sidebars && !empty($sideblocks);
        $sideblocks = array('left' => array(), 'right' => $sideblocks);
        $smarty->assign('userauthinstance', $SESSION->get('authinstance'));
        $smarty->assign('MNETUSER', $SESSION->get('mnetuser'));
        $smarty->assign('SIDEBLOCKS', $sideblocks);
        $smarty->assign('SIDEBARS', $sidebars);
    }
    if (is_array($HEADDATA) && !empty($HEADDATA)) {
        $headers = array_merge($HEADDATA, $headers);
    }
    $smarty->assign_by_ref('HEADERS', $headers);
    if ($USER->get('parentuser')) {
        $smarty->assign('USERMASQUERADING', true);
        $smarty->assign('masqueradedetails', get_string('youaremasqueradingas', 'mahara', display_name($USER)));
        $smarty->assign('becomeyouagain', ' <a href="' . hsc($wwwroot) . 'admin/users/changeuser.php?restore=1">' . get_string('becomeadminagain', 'admin', hsc($USER->get('parentuser')->name)) . '</a>');
    }
    // Define additional html content
    if (get_config('installed')) {
        $additionalhtmlitems = array('ADDITIONALHTMLHEAD' => get_config('additionalhtmlhead'), 'ADDITIONALHTMLTOPOFBODY' => get_config('additionalhtmltopofbody'), 'ADDITIONALHTMLFOOTER' => get_config('additionalhtmlfooter'));
        if ($additionalhtmlitems) {
            foreach ($additionalhtmlitems as $name => $content) {
                $smarty->assign($name, $content);
            }
        }
    }
    // If Cookie Consent is enabled, than define conent
    if (get_config('cookieconsent_enabled')) {
        require_once 'cookieconsent.php';
        $smarty->assign('COOKIECONSENTCODE', get_cookieconsent_code());
    }
    return $smarty;
}