function run($view, $subview, $viewtype)
 {
     //mootools & Ajax preparing stuff
     $this->_type = $viewtype;
     if (!zmgEnv::isRPC()) {
         if ($this->_type == "html") {
             if (ZMG_ADMIN) {
                 $this->_buildAdminToolbar();
             }
             zmgEnv::includeMootools();
             $json =& zmgFactory::getJSON();
             $lifetime = zmgEnv::getSessionLifetime() * 60000;
             //in milliseconds
             //refresh time is 1 minute less than the lifetime assigned in the CMS configuration
             $refreshTime = $lifetime <= 60000 ? 30000 : $lifetime - 60000;
             $this->_constants = array_merge($this->_constants, array("req_uri" => "ZMG.CONST.site_uri + '" . zmgEnv::getAjaxURL() . "'", "res_path" => "ZMG.CONST.site_uri + '/components/com_zoom/var/www/templates/" . $this->_active_template . "'", "base_path" => "'" . zmgGetBasePath() . "'", "refreshtime" => $refreshTime, "sessionid" => $json->encode(zmgEnv::getSessionID()), "sessionname" => $json->encode(zmgEnv::getSessionName())));
             zmgEnv::appendPageHeader(zmgHTML::buildConstScript($this->_constants));
         }
     } else {
         if ($this->_type == "xml") {
             zmgFactory::getRequest()->sendHeaders('xml');
         }
     }
     if ($this->_type == "html") {
         //put the HTML headers in the head section of the parent (hosting) document
         $headers = $this->getHTMLHeaders(zmgEnv::getSiteURL() . '/components/com_zoom/var/www/templates', $this->_type);
         foreach ($headers as $header) {
             zmgEnv::appendPageHeader($header);
         }
     }
     //get template file that belongs to the active view:
     $res =& $this->_getResource('template', $view, $this->_type);
     if ($res) {
         $tpl_file = trim($res->firstChild->getAttribute('href'));
         zmgimport('org.zoomfactory.lib.helpers.zmgAPIHelper');
         $api = new zmgAPIHelper();
         $api->setParam('subview', $subview);
         $this->assign('zmgAPI', $api);
         //the API is accessible for all Smarty templates
         $this->assign('mediapath', $api->getParam('mediapath'));
         $this->display($tpl_file);
     } else {
         return $this->throwError('No template resource found. Unable to run application.');
     }
 }
 /**
  * Checks if a user has the right to edit a medium, or if he/ she already
  * edited the medium before.
  *
  * @param int $id
  * @param string $which
  * @param string $filename
  * @return boolean
  * @access public
  */
 function isEdited($id, $which, $filename = '')
 {
     $db =& zmgDatabase::getDBO();
     $table = zmgFactory::getConfig()->getTableName('editmon');
     $today = time() + intval(zmgEnv::getSessionLifetime());
     $sid = md5(zmgEnv::getSessionToken());
     switch ($which) {
         case 'comment':
             $db->setQuery("SELECT edtid FROM " . $table . " WHERE " . "user_session = '{$sid}' AND comment_time > '{$now}' AND " . "object_id = " . zmgSQLEscape($id));
             break;
         case 'vote':
             $db->setQuery("SELECT edtid FROM " . $table . " WHERE " . "user_session = '{$sid}' AND vote_time > '{$now}' AND " . "object_id = " . zmgSQLEscape($id));
             break;
         case 'pass':
             $db->setQuery("SELECT edtid FROM " . $table . " WHERE " . "user_session = '{$sid}' AND pass_time > '{$now}' AND " . "object_id = " . zmgSQLEscape($id));
             break;
         case 'lightbox':
             $db->setQuery("SELECT edtid FROM " . $table . " WHERE " . "user_session = '{$sid}' AND lightbox_time > '{$now}' AND " . "lightbox_file = '" . zmgSQLEscape($filename) . "'");
             break;
     }
     $result = $db->query();
     if (mysql_num_rows($result) > 0) {
         return true;
     } else {
         return false;
     }
 }