Example #1
0
 /**
  * Searches the database to see if the given extension is installed already
  *
  * @param Array $manifestInformation an array contining the extension type and element name
  * @return Int 0 if the extension does not exisit, the extension id if it does exist
  */
 function checkIfInstalledAlready($manifestInformation)
 {
     //select the right query based on the manifest information
     switch ($manifestInformation["type"]) {
         case "component":
             $query = "SELECT `id` FROM #__components WHERE `option` = '" . $manifestInformation["element"] . "'";
             break;
         case "module":
             $query = "SELECT `id` FROM #__modules WHERE `module` = '" . $manifestInformation["element"] . "'";
             break;
         case "plugin":
             $query = "SELECT `id` FROM #__plugins WHERE `folder` = '" . $manifestInformation["group"] . "' AND `element` = '" . $manifestInformation["element"] . "'";
             break;
         case "template":
             return $manifestInformation["element"];
             break;
         default:
             $query = "";
     }
     //run the query if it was formed
     if ($query != "") {
         $this->_db->setQuery($query);
         $extension_id = intval($this->_db->loadResult());
         //return 0 if the extension was not found
         if (intval($extension_id) < 1) {
             return 0;
         }
         return $extension_id;
     } else {
         return 0;
     }
 }
Example #2
0
 /**
  * Method to get the next ordering value for a group of rows defined by an SQL WHERE clause.
  * This is useful for placing a new item last in a group of items in the table.
  *
  * @param   string   $where  WHERE clause to use for selecting the MAX(ordering) for the table.
  *
  * @return  mixed    Boolean false an failure or the next ordering value as an integer.
  *
  * @link    http://docs.joomla.org/JTable/getNextOrder
  * @since   11.1
  */
 public function getNextOrder($where = '')
 {
     // If there is no ordering field set an error and return false.
     if (!property_exists($this, 'ordering')) {
         $e = new JException(JText::sprintf('JLIB_DATABASE_ERROR_CLASS_DOES_NOT_SUPPORT_ORDERING', get_class($this)));
         $this->setError($e);
         return false;
     }
     // Get the largest ordering value for a given where clause.
     $query = $this->_db->getQuery(true);
     $query->select('MAX(ordering)');
     $query->from($this->_tbl);
     if ($where) {
         $query->where($where);
     }
     $this->_db->setQuery($query);
     $max = (int) $this->_db->loadResult();
     // Check for a database error.
     if ($this->_db->getErrorNum()) {
         $e = new JException(JText::sprintf('JLIB_DATABASE_ERROR_GET_NEXT_ORDER_FAILED', get_class($this), $this->_db->getErrorMsg()));
         $this->setError($e);
         return false;
     }
     // Return the largest ordering value + 1.
     return $max + 1;
 }
Example #3
0
 /**
  * Returns number of images matching the search string
  * (e.g. for pre-filtering, pagination)
  *
  * @param   string  $searchstring The string to use for the search
  * @param   array   $access       Access levels to filter for, null to use the ones of the current user
  * @return  int     The number of images matching the search string
  * @since   1.0.0
  */
 public function getNumPicsBySearch($searchstring, $access = null)
 {
     $query = $this->_db->getQuery(true)->select('COUNT(jg.id)')->from(_JOOM_TABLE_IMAGES . ' AS jg')->leftJoin(_JOOM_TABLE_CATEGORIES . ' AS jgc ON jgc.cid = jg.catid');
     $this->addImageWhere($query);
     $this->addSearchTerms($query);
     $this->_db->setQuery($query);
     return $this->_db->loadResult();
 }
Example #4
0
 /**
  * Get the highest ordering
  *
  * @return int
  */
 public function getMaxOrder()
 {
     if (!in_array('ordering', $this->getColumns())) {
         throw new KDatabaseTableException("The table '" . $this->getTableName() . "' doesn't have a 'ordering' column.");
     }
     $query = 'SELECT MAX(ordering) FROM `#__' . $this->getTableName();
     $this->_db->setQuery($query);
     return (int) $this->_db->loadResult() + 1;
 }
Example #5
0
 /**
  * Get total payment for a wish and user
  *
  * @param   integer  $wishid  Wish ID
  * @param   integer  $uid     User ID
  * @return  integer
  */
 public function getTotalPayment($wishid, $uid)
 {
     if (!$wishid or !$uid) {
         return null;
     }
     $sql = "SELECT SUM(amount) FROM `#__users_transactions` WHERE category='wish' AND referenceid='{$wishid}' AND type='hold' AND uid='{$uid}'";
     $this->_db->setQuery($sql);
     return $this->_db->loadResult();
 }
Example #6
0
 /**
  * Get the total amount of items
  *
  * @return  int
  */
 public function getTotal()
 {
     // Get the data if it doesn't already exist
     if (!isset($this->_total)) {
         $query = $this->_buildCountQuery();
         $this->_db->select($query);
         $this->_total = $this->_db->loadResult();
     }
     return parent::getTotal();
 }
Example #7
0
 /**
  * Process a single record
  *
  * @param   integer  $id
  * @return  object
  */
 public function record($id)
 {
     if (strstr($id, ':')) {
         list($id, $revision) = explode(':', $id);
     }
     $id = intval($id);
     if (!isset($revision)) {
         $revision = 0;
     }
     $this->database->setQuery("SELECT pv.*, pv.doi AS identifier, rt.alias AS type, pv.publication_id\n\t\t\tFROM `#__publication_versions` AS pv\n\t\t\tINNER JOIN `#__publications` AS p ON p.id = pv.publication_id\n\t\t\tINNER JOIN `#__publication_categories` AS rt ON rt.id = p.category\n\t\t\tWHERE pv.id = " . $this->database->quote($id));
     $record = $this->database->loadObject();
     $record->version_id = $record->id;
     $id = $record->publication_id;
     $record->id = $id;
     if (!$record->identifier) {
         $record->identifier = self::$base . '/' . ltrim(\Route::url('index.php?option=com_publications&id=' . $id . ($record->version_id ? '&v=' . $record->version_id : '')), '/');
     }
     $record->base = $this->name();
     $record->type = $record->base . ':' . $record->type;
     $record->description = strip_tags($record->description);
     $record->description = trim($record->description);
     $this->database->setQuery("SELECT pv.submitted\n\t\t\tFROM `#__publication_versions` pv, `#__publications` p\n\t\t\tWHERE p.id = pv.publication_id AND p.id = " . $this->database->quote($id) . "\n\t\t\tORDER BY pv.submitted DESC LIMIT 1");
     $record->date = $this->database->loadResult();
     $this->database->setQuery("SELECT pa.name\n\t\t\tFROM `#__publication_authors` pa, `#__publication_versions` pv, `#__publications` p\n\t\t\tWHERE pa.publication_version_id = pv.id AND pa.role != 'submitter' AND pv.publication_id = p.id AND p.id=" . $this->database->quote($id) . "\n\t\t\tORDER BY pa.name");
     $record->creator = $this->database->loadColumn();
     $this->database->setQuery("SELECT DISTINCT t.raw_tag\n\t\t\tFROM `#__tags` t, `#__tags_object` tos\n\t\t\tWHERE t.id = tos.tagid AND tos.objectid=" . $this->database->quote($id) . " AND tos.tbl='publications' AND t.admin=0\n\t\t\tORDER BY t.raw_tag");
     $record->subject = $this->database->loadColumn();
     // Relations
     $record->relation = array();
     $this->database->setQuery("SELECT *\n\t\t\tFROM `#__citations` AS a\n\t\t\tLEFT JOIN `#__citations_assoc` AS n ON n.`cid`=a.`id`\n\t\t\tWHERE n.`tbl`='publication' AND n.`oid`=" . $this->database->quote($id) . " AND n.`type`='owner' AND a.`published`=1\n\t\t\tORDER BY `year` DESC");
     $references = $this->database->loadObjectList();
     if (count($references) && file_exists(PATH_CORE . DS . 'components' . DS . 'com_citations' . DS . 'helpers' . DS . 'format.php')) {
         include_once PATH_CORE . DS . 'components' . DS . 'com_citations' . DS . 'helpers' . DS . 'format.php';
         $formatter = new \Components\Citations\Helpers\Format();
         $formatter->setTemplate('apa');
         foreach ($references as $reference) {
             $cite = strip_tags(html_entity_decode($reference->formatted ? $reference->formatted : \Components\Citations\Helpers\Format::formatReference($reference, '')));
             $cite = str_replace('&quot;', '"', $cite);
             $record->relation[] = array('type' => 'isReferencedBy', 'value' => trim($cite));
         }
     }
     $this->database->setQuery("SELECT *\n\t\t\tFROM `#__citations` AS a\n\t\t\tLEFT JOIN `#__citations_assoc` AS n ON n.`cid`=a.`id`\n\t\t\tWHERE n.`tbl`='publication' AND n.`oid`=" . $this->database->quote($id) . " AND n.`type`!='owner' AND a.`published`=1\n\t\t\tORDER BY `year` DESC");
     $references = $this->database->loadObjectList();
     if (count($references) && file_exists(PATH_CORE . DS . 'components' . DS . 'com_citations' . DS . 'helpers' . DS . 'format.php')) {
         include_once PATH_CORE . DS . 'components' . DS . 'com_citations' . DS . 'helpers' . DS . 'format.php';
         $formatter = new \Components\Citations\Helpers\Format();
         $formatter->setTemplate('apa');
         foreach ($references as $reference) {
             $cite = strip_tags(html_entity_decode($reference->formatted ? $reference->formatted : \Components\Citations\Helpers\Format::formatReference($reference, '')));
             $cite = str_replace('&quot;', '"', $cite);
             $record->relation[] = array('type' => 'references', 'value' => trim($cite));
         }
     }
     return $record;
 }
Example #8
0
 /**
  * Mark an entry as opted out
  *
  * @return  mixed
  */
 public function award()
 {
     if (!$this->uid) {
         return NULL;
     }
     $opts = new ModIncrementalRegistrationOptions();
     $awardPer = $opts->getAwardPerField();
     $fieldMap = array('name' => 'Fullname', 'orgtype' => 'Employment', 'organization' => 'Organization', 'countryorigin' => 'Citizenship', 'countryresident' => 'Residency', 'gender' => 'Sex', 'url' => 'URL', 'reason' => 'Reason', 'race' => 'Race', 'phone' => 'Phone', 'disability' => 'Disability');
     $alreadyComplete = 0;
     $eligible = array();
     $newAmount = 0;
     $completeSql = 'UPDATE `#__profile_completion_awards` SET edited_profile = 1';
     $optedOut = NULL;
     foreach ($this->awards as $k => $complete) {
         if ($k === 'opted_out') {
             $optedOut = $complete;
             continue;
         }
         if ($complete) {
             continue;
         }
         if ($k === 'picture') {
             self::$dbh->setQuery('SELECT picture FROM `#__xprofiles` WHERE uidNumber = ' . $this->uid);
             if (self::$dbh->loadResult()) {
                 $completeSql .= ', ' . $k . ' = 1';
                 $alreadyComplete += $awardPer;
             } else {
                 $eligible['picture'] = 1;
             }
             continue;
         }
         $regField = $fieldMap[$k];
         if ((bool) $this->profile->get($k)) {
             $completeSql .= ', ' . $k . ' = 1';
             $alreadyComplete += $awardPer;
         } else {
             $eligible[$k == 'url' ? 'web' : $k] = 1;
         }
     }
     self::$dbh->setQuery('SELECT SUM(amount) AS amount FROM `#__users_transactions` WHERE type = \'deposit\' AND category = \'registration\' AND uid = ' . $this->uid);
     $prior = self::$dbh->loadResult();
     self::$dbh->setQuery($completeSql . ' WHERE user_id = ' . $this->uid);
     self::$dbh->execute();
     if ($alreadyComplete) {
         self::$dbh->setQuery('SELECT COALESCE((SELECT balance FROM `#__users_transactions` WHERE uid = ' . $this->uid . ' AND id = (SELECT MAX(id) FROM `#__users_transactions` WHERE uid = ' . $this->uid . ')), 0)');
         $newAmount = self::$dbh->loadResult() + $alreadyComplete;
         $BTL = new \Hubzero\Bank\Teller(self::$dbh, $this->uid);
         $BTL->deposit($alreadyComplete, 'Profile completion award', 'registration', 0);
     }
     return array('prior' => $prior, 'new' => $alreadyComplete, 'eligible' => $eligible, 'opted_out' => $optedOut);
 }
 /**
  * Get the number of all items
  *
  * @return  integer
  */
 public function getTotal()
 {
     if (empty($this->total)) {
         $query = $this->buildCountQuery();
         if ($query === false) {
             $sql = (string) $this->buildQuery(false);
             $query = $this->_db->getQuery(true)->select('COUNT(*)')->from("({$sql}) AS a");
         }
         $this->_db->setQuery((string) $query);
         $this->_db->execute();
         $this->total = $this->_db->loadResult();
     }
     return $this->total;
 }
Example #10
0
File: model.php Project: 01J/topm
 /**
  * Get the number of all items
  *
  * @return  integer
  */
 public function getTotal()
 {
     if (is_null($this->total)) {
         $query = $this->buildCountQuery();
         if ($query === false) {
             $subquery = $this->buildQuery(false);
             $subquery->clear('order');
             $query = $this->_db->getQuery(true)->select('COUNT(*)')->from("(" . (string) $subquery . ") AS a");
         }
         $this->_db->setQuery((string) $query);
         $this->total = $this->_db->loadResult();
     }
     return $this->total;
 }
 /**
  * Returns a record count for the query.
  *
  * @param   JDatabaseQuery|string  $query  The query.
  *
  * @return  integer  Number of rows for query.
  *
  * @since   12.2
  */
 protected function _getListCount($query)
 {
     // Use fast COUNT(*) on JDatabaseQuery objects if there no GROUP BY or HAVING clause:
     if ($query instanceof JDatabaseQuery && $query->type == 'select' && $query->group === null && $query->having === null) {
         $query = clone $query;
         $query->clear('select')->clear('order')->clear('limit')->select('COUNT(*)');
         $this->_db->setQuery($query);
         return (int) $this->_db->loadResult();
     }
     // Otherwise fall back to inefficient way of counting all results.
     $this->_db->setQuery($query);
     $this->_db->execute();
     return (int) $this->_db->getNumRows();
 }
Example #12
0
 /**
  * Searches the database to see if the given extension is installed already
  *
  * @param Array $manifestInformation an array contining the extension type and element name
  * @return Int 0 if the extension does not exisit, the extension id if it does exist
  */
 function checkIfInstalledAlready($manifestInformation)
 {
     //select the right query based on the manifest information
     switch ($manifestInformation["type"]) {
         case "component":
             if (version_compare(JVERSION, '1.6.0', 'ge')) {
                 // Joomla! 1.6+ code here
                 $query = "SELECT `extension_id` AS id FROM #__extensions WHERE `type` = 'component' AND `element` = '" . $manifestInformation["element"] . "'";
             } else {
                 // Joomla! 1.5 code here
                 $query = "SELECT `id` FROM #__components WHERE `option` = '" . $manifestInformation["element"] . "'";
             }
             break;
         case "module":
             $mname = $manifestInformation["element"];
             if (version_compare(JVERSION, '1.6.0', 'ge')) {
                 // Joomla! 1.6+ code here
                 $query = "SELECT `extension_id` AS id FROM #__extensions WHERE `type` = 'module' AND `element` = '" . $mname . "'";
             } else {
                 // Joomla! 1.5 code here
                 $query = "SELECT `id` FROM #__modules WHERE `module` = '" . $mname . "'";
             }
             break;
         case "plugin":
             if (version_compare(JVERSION, '1.6.0', 'ge')) {
                 // Joomla! 1.6+ code here
                 $query = "SELECT `extension_id` AS id FROM #__extensions WHERE `type` = 'plugin' AND `folder` = '" . $manifestInformation["group"] . "' AND `element` = '" . $manifestInformation["element"] . "'";
             } else {
                 // Joomla! 1.5 code here
                 $query = "SELECT `id` FROM #__plugins WHERE `folder` = '" . $manifestInformation["group"] . "' AND `element` = '" . $manifestInformation["element"] . "'";
             }
             break;
         default:
             $query = "";
     }
     //run the query if it was formed
     if ($query != "") {
         $this->_db->setQuery($query);
         $extension_id = intval($this->_db->loadResult());
         //return 0 if the extension was not found
         if (intval($extension_id) < 1) {
             return 0;
         }
         return $extension_id;
     } else {
         return 0;
     }
 }
 /**
  * Returns a record count for the query
  *
  * @param   string  $query  The query.
  *
  * @return  integer  Number of rows for query
  *
  * @since   12.2
  */
 protected function _getListCount($query)
 {
     if ($query instanceof JDatabaseQuery) {
         // Create COUNT(*) query to allow database engine to optimize the query.
         $query = clone $query;
         $query->clear('select')->clear('order')->select('COUNT(*)');
         $this->_db->setQuery($query);
         return (int) $this->_db->loadResult();
     } else {
         /* Performance of this query is very bad as it forces database engine to go
          * through all items in the database. If you don't use JDatabaseQuery object,
          * you should override this function in your model.
          */
         $this->_db->setQuery($query);
         $this->_db->execute();
         return $this->_db->getNumRows();
     }
 }
Example #14
0
 /**
  * Check a room to determine whether it can be deleted or not, if yes then delete it
  * 
  * When delete a room, we will need to make sure that all related
  * Reservation of that room must be removed first 
  *  
  * @param 	int 	    $roomId
  * 
  * @return 	boolean     True if a room is safe to be deleted
  *                      False otherwise
  */
 public function canDeleteRoom($roomId = 0)
 {
     $query = $this->_dbo->getQuery(true);
     $query->select('COUNT(*)')->from($this->_dbo->quoteName('#__sr_reservation_room_xref'))->where('room_id = ' . $this->_dbo->quote($roomId));
     $this->_dbo->setQuery($query);
     $result = (int) $this->_dbo->loadResult();
     if ($result > 0) {
         return false;
     }
     $query->clear();
     $query->delete('')->from($this->_dbo->quoteName('#__sr_rooms'))->where('id = ' . $this->_dbo->quote($roomId));
     $this->_dbo->setQuery($query);
     $result = $this->_dbo->execute();
     if (!$result) {
         return false;
     }
     return true;
 }
Example #15
0
 /**
  * Method to get the next ordering value for a group of rows defined by an SQL WHERE clause.
  * This is useful for placing a new item last in a group of items in the table.
  *
  * @param	string	WHERE clause to use for selecting the MAX(ordering) for the table.
  * @return	mixed	Boolean false an failure or the next ordering value as an integer.
  * @since	1.0
  * @link	http://docs.joomla.org/JTable/getNextOrder
  */
 public function getNextOrder($where = '')
 {
     // If there is no ordering field set an error and return false.
     if (!property_exists($this, 'ordering')) {
         $this->setError(get_class($this) . ' does not support ordering');
         return false;
     }
     // Prepare the WHERE clause if set.
     $where = $where ? ' WHERE ' . $where : '';
     // Get the largest ordering value for a given where clause.
     $this->_db->setQuery('SELECT MAX(ordering)' . ' FROM `' . $this->_tbl . '`' . $where);
     $max = (int) $this->_db->loadResult();
     // Check for a database error.
     if ($this->_db->getErrorNum()) {
         $this->setError($this->_db->getErrorMsg());
         return false;
     }
     // Return the largest ordering value + 1.
     return $max + 1;
 }
Example #16
0
 /**
  * Build query for retrieving records
  *
  * @param   array   $filters
  * @return  string
  */
 public function records($filters = array())
 {
     if (isset($filters['set']) && $filters['set']) {
         if (!preg_match('/^publications\\:(.+)/i', $filters['set'], $matches)) {
             return '';
         }
         $set = trim($matches[1]);
         $this->database->setQuery("SELECT t.id FROM `#__publication_categories` AS t WHERE t.alias=" . $this->database->quote($set));
         $this->set('type', $this->database->loadResult());
         if (!$this->get('type')) {
             return '';
         }
     }
     $query = "SELECT CONCAT(p.id, ':', pv.version_number) AS id, " . $this->database->quote($this->name()) . " AS `base`\n\t\t\t\tFROM `#__publications` AS p\n\t\t\t\tINNER JOIN `#__publication_versions` AS pv ON pv.publication_id = p.id\n\t\t\t\tWHERE pv.state=1";
     if ($type = $this->get('type')) {
         $query .= " AND p.category=" . $this->database->quote($type);
     }
     if (isset($filters['from']) && $filters['from']) {
         $d = explode('-', $filters['from']);
         $filters['from'] = $d[0];
         $filters['from'] .= '-' . (isset($d[1]) ? $d[1] : '00');
         $filters['from'] .= '-' . (isset($d[2]) ? $d[2] : '00');
         if (!preg_match("/([0-9]{4})-([0-9]{2})-([0-9]{2})[ ]([0-9]{2}):([0-9]{2}):([0-9]{2})/", $filters['from'])) {
             $filters['from'] .= ' 00:00:00';
         }
         $query .= " AND (\n\t\t\t\t(CASE WHEN pv.`accepted` != '0000-00-00 00:00:00' THEN pv.`accepted` ELSE pv.`published_up` END) >= " . $this->database->quote($filters['from']) . "\n\t\t\t)";
     }
     if (isset($filters['until']) && $filters['until']) {
         $d = explode('-', $filters['until']);
         $filters['until'] = $d[0];
         $filters['until'] .= '-' . (isset($d[1]) ? $d[1] : '00');
         $filters['until'] .= '-' . (isset($d[2]) ? $d[2] : '00');
         if (!preg_match("/([0-9]{4})-([0-9]{2})-([0-9]{2})[ ]([0-9]{2}):([0-9]{2}):([0-9]{2})/", $filters['until'])) {
             $filters['until'] .= ' 00:00:00';
         }
         $query .= " AND (\n\t\t\t\t(CASE WHEN pv.`accepted` != '0000-00-00 00:00:00' THEN pv.`accepted` ELSE pv.`published_up` END) < " . $this->database->quote($filters['until']) . "\n\t\t\t)";
     }
     return $query;
 }
Example #17
0
 function getData()
 {
     if (!is_null($this->data)) {
         return $this->data;
     }
     $limitstart = RdbsRequest::getVar('limitstart', '0', '', 'int');
     $limit = $this->getUserStateFromRequest('limit', 50);
     $this->db->setQuery("SELECT count(*) FROM {$this->table} ");
     $rc = $this->db->loadResult();
     if ($this->db->getErrorNum()) {
         return RdbsError::raiseError(500, $this->db->stderr());
     }
     $query = "SELECT * FROM {$this->table} ";
     $this->db->setQuery($query, $limitstart, $limit);
     $this->data = $this->db->loadObjectList();
     if ($this->db->getErrorNum()) {
         return RdbsError::raiseError(500, $this->db->stderr());
     }
     $this->page = new RdbsPagination($rc, $limitstart, $limit);
     $this->lists = array();
     return $this->data;
 }
Example #18
0
 /**
  * Save a new node
  * 
  * @param   int     $parentId The parent node id
  * @return  boolean
  */
 public function saveNode($parentId)
 {
     $query = $this->_dbo->getQuery(true);
     $context = 'com_solidres.edit.category';
     $app = JFactory::getApplication();
     // get the lft value of parent id
     $query->select('lft');
     $query->from($this->_tbl);
     $query->where('id = ' . $this->_dbo->quote($parentId));
     $this->_dbo->setQuery($query);
     $parentLft = $this->_dbo->loadResult();
     // Move all rgt by 2,give space for new node
     $query->clear();
     $query->update($this->_tbl);
     $query->set('rgt = rgt + 2');
     $query->where('rgt > ' . $this->_dbo->quote($parentLft));
     $this->_dbo->setQuery($query);
     if (!$this->_dbo->execute()) {
         $errorMsg = JText::sprintf('SR_DATABASE_ERROR_MOVE_FAILED', get_class($this), $this->_dbo->getErrorMsg());
         JError::raiseWarning('', $errorMsg);
         $this->_unlock();
         return false;
     }
     // Move all lft by 2, give space for new node
     $query->clear();
     $query->update($this->_tbl);
     $query->set('lft = lft + 2');
     $query->where('lft > ' . $this->_dbo->quote($parentLft));
     $this->_dbo->setQuery($query);
     if (!$this->_dbo->execute()) {
         $errorMsg = JText::sprintf('SR_DATABASE_ERROR_MOVE_FAILED', get_class($this), $this->_dbo->getErrorMsg());
         JError::raiseWarning('', $errorMsg);
         $this->_unlock();
         return false;
     }
     $app->setUserState($context . '.parentlft', $parentLft);
     return true;
 }
Example #19
0
 /**
  * Remove template entires from the appropriate tables
  *
  * @param   string  $name    Template element name
  * @param   int     $client  Client id
  * @return  bool
  **/
 public function deleteTemplateEntry($element, $client = 1)
 {
     if ($this->baseDb->tableExists('#__extensions')) {
         $query = "DELETE FROM `#__extensions` WHERE `type` = 'template' AND `element` = '{$element}' AND `client_id` = '{$client}'";
         $this->baseDb->setQuery($query);
         $this->baseDb->query();
         $query = "DELETE FROM `#__template_styles` WHERE `template` = '{$element}' AND `client_id` = '{$client}'";
         $this->baseDb->setQuery($query);
         $this->baseDb->query();
         // Now make sure we have an enabled template (don't really care which one it is)
         $query = "SELECT `id` FROM `#__template_styles` WHERE `home` = 1 AND `client_id` = '{$client}'";
         $this->baseDb->setQuery($query);
         if (!$this->baseDb->loadResult()) {
             $query = "SELECT `id` FROM `#__template_styles` WHERE `client_id` = '{$client}' ORDER BY `id` DESC LIMIT 1";
             $this->baseDb->setQuery($query);
             if ($id = $this->baseDb->loadResult()) {
                 $query = "UPDATE `#__template_styles` SET `home` = 1 WHERE `id` = '{$id}'";
                 $this->baseDb->setQuery($query);
                 $this->baseDb->query();
             }
         }
     }
 }
Example #20
0
 /**
  * Method to get the page title of any menu item that is linked to the
  * content item, if it exists and is set.
  *
  * @param   string  $url  The url of the item.
  *
  * @return  mixed  The title on success, null if not found.
  *
  * @since   2.5
  * @throws  Exception on database error.
  */
 protected function getItemMenuTitle($url)
 {
     JLog::add('FinderIndexerAdapter::getItemMenuTitle', JLog::INFO);
     $return = null;
     // Set variables
     $user = JFactory::getUser();
     $groups = implode(',', $user->getAuthorisedViewLevels());
     // Build a query to get the menu params.
     $sql = $this->db->getQuery(true);
     $sql->select($this->db->quoteName('params'));
     $sql->from($this->db->quoteName('#__menu'));
     $sql->where($this->db->quoteName('link') . ' = ' . $this->db->quote($url));
     $sql->where($this->db->quoteName('published') . ' = 1');
     $sql->where($this->db->quoteName('access') . ' IN (' . $groups . ')');
     // Get the menu params from the database.
     $this->db->setQuery($sql);
     $params = $this->db->loadResult();
     // Check for a database error.
     if ($this->db->getErrorNum()) {
         // Throw database error exception.
         throw new Exception($this->db->getErrorMsg(), 500);
     }
     // Check the results.
     if (empty($params)) {
         return $return;
     }
     // Instantiate the params.
     $params = json_decode($params);
     // Get the page title if it is set.
     if ($params->page_title) {
         $return = $params->page_title;
     }
     return $return;
 }
Example #21
0
 /**
  * Process a single record
  *
  * @param   integer  $id
  * @return  object
  */
 public function record($id)
 {
     if (strstr($id, ':')) {
         list($id, $revision) = explode(':', $id);
     }
     $id = intval($id);
     if (!isset($revision)) {
         $revision = 0;
     }
     $this->database->setQuery("SELECT r.id, r.id AS identifier, r.title, r.introtext AS description, r.fulltxt, r.created, r.publish_up, r.alias, rt.alias AS type\n\t\t\tFROM `#__resources` AS r\n\t\t\tINNER JOIN `#__resource_types` AS rt ON r.type = rt.id\n\t\t\tWHERE r.id = " . $this->database->quote($id));
     $record = $this->database->loadObject();
     $record->base = $this->name();
     $record->type = $record->base . ':' . $record->type;
     if ($revision) {
         $this->database->setQuery("SELECT *\n\t\t\t\tFROM `#__tool_version`\n\t\t\t\tWHERE toolname=" . $this->database->quote($record->alias) . " AND revision=" . $this->database->quote($revision) . "\n\t\t\t\tLIMIT 1");
         $tool = $this->database->loadObject();
         if ($tool->id) {
             $record->title .= ' [version ' . $tool->version . ']';
             $record->fulltxt = $tool->fulltxt;
             $record->publish_up = $tool->released;
         }
     }
     $record->date = $record->created;
     if ($record->publish_up && $record->publish_up != $this->database->getNullDate()) {
         $record->date = $record->publish_up;
     }
     if (!$record->description) {
         $record->description = $record->fulltxt;
         $record->description = preg_replace("#<nb:(.*?)>(.*?)</nb:(.*?)>#s", '', $record->description);
     }
     $record->description = strip_tags($record->description);
     $record->description = trim($record->description);
     unset($record->publish_up);
     unset($record->created);
     unset($record->fulltxt);
     $isTool = 0;
     if ($record->alias) {
         $this->database->setQuery("SELECT id\n\t\t\t\tFROM `#__tool`\n\t\t\t\tWHERE toolname=" . $this->database->quote($record->alias) . "\n\t\t\t\tLIMIT 1");
         $isTool = $this->database->loadResult();
     }
     if ($revision) {
         /*"SELECT a.`doi`
         		FROM `#__doi_mapping` AS a
         		LEFT JOIN `#__tool_version` AS v ON v.id=a.versionid
         		WHERE a.rid=" . $this->database->quote($id) . " AND v.revision=" . $this->database->quote($revision) . "
         		LIMIT 1"*/
         $this->database->setQuery("SELECT a.`doi`\n\t\t\t\tFROM `#__doi_mapping` AS a\n\t\t\t\tWHERE a.rid=" . $this->database->quote($id) . " AND a.local_revision=" . $this->database->quote($revision) . "\n\t\t\t\tLIMIT 1");
     } else {
         $this->database->setQuery("SELECT a.`doi`\n\t\t\t\tFROM `#__doi_mapping` AS a\n\t\t\t\tWHERE a.rid=" . $this->database->quote($id) . "\n\t\t\t\tORDER BY `versionid` DESC LIMIT 1");
     }
     $record->identifier = $this->identifier($id, $this->database->loadResult(), $revision);
     $this->database->setQuery("SELECT DISTINCT t.raw_tag\n\t\t\tFROM `#__tags` t, `#__tags_object` tos\n\t\t\tWHERE t.id = tos.tagid AND tos.objectid=" . $this->database->quote($id) . " AND tos.tbl='resources' AND t.admin=0\n\t\t\tORDER BY t.raw_tag");
     $record->subject = $this->database->loadColumn();
     $record->relation = array();
     $this->database->setQuery("SELECT r.id, r.title, r.type, r.logical_type AS logicaltype, r.created, r.created_by,\n\t\t\tr.published, r.publish_up, r.path, r.access, t.type AS logicaltitle, rt.type AS typetitle, r.standalone\n\t\t\tFROM `#__resources` AS r\n\t\t\tINNER JOIN `#__resource_types` AS rt ON r.type=rt.id\n\t\t\tINNER JOIN `#__resource_assoc` AS a ON r.id=a.child_id\n\t\t\tLEFT JOIN `#__resource_types` AS t ON r.logical_type=t.id\n\t\t\tWHERE r.published=1 AND a.parent_id=" . $this->database->quote($id) . "\n\t\t\tORDER BY a.ordering, a.grouping");
     if ($children = $this->database->loadObjectList()) {
         require_once PATH_CORE . DS . 'components' . DS . 'com_resources' . DS . 'helpers' . DS . 'html.php';
         require_once PATH_CORE . DS . 'components' . DS . 'com_resources' . DS . 'tables' . DS . 'type.php';
         foreach ($children as $child) {
             $uri = \Components\Resources\Helpers\Html::processPath('com_resources', $child, $id, 3);
             if (substr($uri, 0, 4) != 'http') {
                 $uri = self::$base . '/' . ltrim($uri, '/');
             }
             $record->relation[] = array('type' => 'hasPart', 'value' => $uri);
         }
     }
     $this->database->setQuery("SELECT DISTINCT r.id\n\t\t\tFROM `#__resources` AS r\n\t\t\tINNER JOIN `#__resource_assoc` AS a ON r.id=a.parent_id\n\t\t\tWHERE r.published=1 AND a.child_id=" . $this->database->quote($id) . "\n\t\t\tORDER BY a.ordering, a.grouping");
     if ($parents = $this->database->loadObjectList()) {
         foreach ($parents as $parent) {
             $record->relation[] = array('type' => 'isPartOf', 'value' => $this->identifier($parent->id, 0));
         }
     }
     if ($isTool) {
         if ($revision) {
             $this->database->setQuery("SELECT n.uidNumber AS id,\n\t\t\t\t\t\tCASE WHEN t.name!='' AND t.name IS NOT NULL THEN t.name\n\t\t\t\t\t\tELSE n.name\n\t\t\t\t\t\tEND AS `name`\n\t\t\t\t\tFROM `#__tool_authors` AS t, `#__xprofiles` AS n, `#__tool_version` AS v\n\t\t\t\t\tWHERE n.uidNumber=t.uid AND t.toolname=" . $this->database->quote($record->alias) . " AND v.id=t.version_id and v.state<>3\n\t\t\t\t\tAND t.revision=" . $this->database->quote($revision) . "\n\t\t\t\t\tORDER BY t.ordering");
             $record->creator = $this->database->loadColumn();
             /*$record->relation[] = array(
             			'type'  => 'isVersionOf',
             			'value' => $this->identifier($id, '', 0)
             		);*/
         }
         $this->database->setQuery("SELECT v.id, v.revision, d.*\n\t\t\t\tFROM `#__tool_version` as v\n\t\t\t\tLEFT JOIN `#__doi_mapping` as d\n\t\t\t\tON d.alias = v.toolname\n\t\t\t\tAND d.local_revision=v.revision\n\t\t\t\tWHERE v.toolname = " . $this->database->quote($record->alias) . "\n\t\t\t\tORDER BY v.state DESC, v.revision DESC");
         $versions = $this->database->loadObjectList();
         foreach ($versions as $i => $v) {
             if (!$v->revision || $v->revision == $revision) {
                 continue;
             }
             $record->relation[] = array('type' => 'hasVersion', 'value' => $this->identifier($id, $v->doi, $v->revision));
         }
     }
     if (!isset($record->creator)) {
         $this->database->setQuery("SELECT \n\t\t\t\t\tCASE WHEN a.name!='' AND a.name IS NOT NULL THEN a.name\n\t\t\t\t\tELSE n.name\n\t\t\t\t\tEND AS `name`\n\t\t\t\tFROM `#__author_assoc` AS a\n\t\t\t\tLEFT JOIN `#__xprofiles` AS n ON n.uidNumber=a.authorid\n\t\t\t\tWHERE a.subtable='resources' AND a.subid=" . $this->database->quote($id) . " AND a.role!='submitter'\n\t\t\t\tORDER BY a.ordering, a.name");
         $record->creator = $this->database->loadColumn();
     }
     $this->database->setQuery("SELECT *\n\t\t\tFROM `#__citations` AS a\n\t\t\tINNER JOIN `#__citations_assoc` AS n ON n.`cid`=a.`id`\n\t\t\tWHERE n.`tbl`='resource' AND n.`oid`=" . $this->database->quote($id) . " AND a.`published`=1\n\t\t\tORDER BY `year` DESC");
     $references = $this->database->loadObjectList();
     if (count($references) && file_exists(PATH_CORE . DS . 'components' . DS . 'com_citations' . DS . 'helpers' . DS . 'format.php')) {
         include_once PATH_CORE . DS . 'components' . DS . 'com_citations' . DS . 'helpers' . DS . 'format.php';
         $formatter = new \Components\Citations\Helpers\Format();
         $formatter->setTemplate('apa');
         foreach ($references as $reference) {
             //<dcterms:isReferencedBy>uytruytry</dcterms:isReferencedBy>
             //<dcterms:isVersionOf>jgkhfjf</dcterms:isVersionOf>
             $cite = strip_tags(html_entity_decode($reference->formatted ? $reference->formatted : \Components\Citations\Helpers\Format::formatReference($reference, '')));
             $cite = str_replace('&quot;', '"', $cite);
             $record->relation[] = array('type' => 'references', 'value' => trim($cite));
         }
     }
     return $record;
 }
Example #22
0
 /**
  * Check for region data for a date
  *
  * @param      object $db       JDatabase
  * @param      string $yearmonth YYYY-MM
  * @return     boolean True if data is found
  */
 public static function check_for_regiondata($db, $yearmonth)
 {
     $sql = "SELECT COUNT(datetime)\n\t\t\t\tFROM regionvals\n\t\t\t\tWHERE datetime LIKE " . $db->quote($yearmonth . '-%');
     $db->setQuery($sql);
     $result = $db->loadResult();
     if ($result && $result > 0) {
         return true;
     }
     return false;
 }
Example #23
0
 /**
  * Get active columns for a user
  *
  * @param   integer  $uid
  * @return  array
  */
 public function getActiveColumns($uid)
 {
     $uid = (int) $uid;
     self::$dbh->setQuery('SELECT irl.* FROM `#__incremental_registration_groups` irg LEFT JOIN `#__incremental_registration_group_label_rel` irglr ON irglr.group_id = irg.id INNER JOIN `#__incremental_registration_labels` irl ON irl.id = irglr.label_id WHERE irg.hours <= (SELECT (unix_timestamp(current_timestamp) - unix_timestamp(registerDate))/60/60 AS hours FROM `#__users` WHERE id = ' . $uid . ')');
     $cols = self::$dbh->loadAssocList();
     // no data we want, don't bother
     if (!$cols) {
         return array();
     }
     self::$dbh->setQuery('SELECT coalesce((SELECT opted_out FROM `#__profile_completion_awards` WHERE user_id = ' . $uid . '), 0)');
     $times = self::$dbh->loadResult();
     if ($times > 0) {
         self::$dbh->setQuery('SELECT (unix_timestamp() - unix_timestamp(last_bothered))/60/60 > (SELECT coalesce((SELECT hours FROM `#__incremental_registration_popover_recurrence` WHERE idx = ' . ($times - 1) . '), (SELECT hours FROM `#__incremental_registration_popover_recurrence` ORDER BY idx DESC LIMIT 1))) FROM `#__profile_completion_awards` WHERE user_id = ' . $uid);
         // opt-out period is in effect
         if (!self::$dbh->loadResult()) {
             return array();
         }
     }
     $colNames = array();
     $wantRace = false;
     $wantDisability = false;
     foreach ($cols as $col) {
         if ($col['field'] == 'race') {
             $wantRace = true;
             continue;
         }
         if ($col['field'] == 'disability') {
             $wantDisability = true;
             continue;
         }
         $colNames[] = $col['field'];
     }
     self::$dbh->setQuery('SELECT ' . implode(', ', $colNames) . ' FROM `#__xprofiles` WHERE uidNumber = ' . $uid);
     $profile = self::$dbh->loadAssoc();
     $neededCols = array();
     $nonUS = false;
     foreach ($cols as $col) {
         if (!array_key_exists($col['field'], $profile)) {
             continue;
         }
         if ($col['field'] == 'mailPreferenceOption') {
             if ($profile[$col['field']] == -1) {
                 $neededCols['mailPreferenceOption'] = $col['label'];
             }
             continue;
         }
         if (!trim($profile[$col['field']])) {
             $neededCols[$col['field']] = $col['label'];
         }
     }
     if ($wantRace) {
         self::$dbh->setQuery('SELECT countryorigin FROM `#__xprofiles` WHERE uidNumber = ' . $uid);
         if (!($country = self::$dbh->loadResult()) || strtolower($country) == 'us') {
             self::$dbh->setQuery('SELECT COUNT(*) FROM `#__xprofiles_race` WHERE uidNumber = ' . $uid);
             if (!self::$dbh->loadResult()) {
                 $neededCols['race'] = 'Race';
             }
         }
     }
     if ($wantDisability) {
         self::$dbh->setQuery('SELECT 1 FROM `#__xprofiles_disability` WHERE uidNumber = ' . $uid . ' LIMIT 1');
         if (!self::$dbh->loadResult()) {
             $neededCols['disability'] = 'Disability';
         }
     }
     return $neededCols;
 }
Example #24
0
 /**
  * Event call for displaying usage data
  *
  * @param      string $option        Component name
  * @param      string $task          Component task
  * @param      object $db            JDatabase
  * @param      array  $months        Month names (Jan -> Dec)
  * @param      array  $monthsReverse Month names in reverse (Dec -> Jan)
  * @param      string $enddate       Time period
  * @return     string HTML
  */
 public function onUsageDisplay($option, $task, $db, $months, $monthsReverse, $enddate)
 {
     // Check if our task is the area we want to return results for
     if ($task) {
         if (!in_array($task, $this->onUsageAreas()) && !in_array($task, array_keys($this->onUsageAreas()))) {
             return '';
         }
     }
     $config = Component::params($option);
     // Incoming
     $period = Request::getVar('period', 'prior12');
     $selectedPeriod = Request::getVar('selectedPeriod', '');
     if (!$selectedPeriod) {
         $db->setQuery("SELECT MAX(datetime) FROM summary_misc_vals");
         $lastdate = $db->loadResult();
         if ($lastdate) {
             $defaultMonth = substr($lastdate, 5, 2);
             $defaultYear = substr($lastdate, 0, 4);
         } else {
             $defaultMonth = date("m");
             $defaultYear = date("Y");
         }
         $selectedPeriod = $defaultYear . '-' . $defaultMonth;
     }
     $checkyear = substr($selectedPeriod, 0, 4);
     $checkmonth = substr($selectedPeriod, 5, 2);
     if ($checkyear <= '2007') {
         if ($checkyear < '2007') {
             $page = 'old';
         } else {
             if ($checkyear == '2007') {
                 if ($checkmonth < '10') {
                     $page = 'old';
                 } else {
                     $page = 'new';
                 }
             }
         }
     } else {
         $page = 'new';
     }
     if ($period == 'nice') {
         $page = 'old';
         $selectedPeriod = '2007-09';
     }
     // Get and set some vars
     $cur_year = floor(date("Y"));
     $cur_month = floor(date("n"));
     $year_data_start = 2000;
     $datetime = $selectedPeriod . '-00 00:00:00';
     // Set the pathway
     Pathway::append(Lang::txt('PLG_USAGE_PERIOD_' . strtoupper($period)), 'index.php?option=' . $option . '&task=' . $task . '&period=' . $period);
     // Build the HTML
     $html = $this->_navlinks($option, $task, $period);
     $html .= '<form method="post" action="' . Route::url('index.php?option=' . $option . '&task=' . $task . '&period=' . $period) . '">' . "\n";
     $html .= "\t" . '<fieldset class="filters"><label>' . Lang::txt('PLG_USAGE_SHOW_DATA_FOR') . ': ';
     $html .= '<select name="selectedPeriod">' . "\n";
     switch ($period) {
         case '12':
         case 'prior12':
         case 'nice':
             $option = 'prior12';
             $period = '12';
             $arrayMonths = array_values($months);
             for ($i = $cur_year; $i >= $year_data_start; $i--) {
                 foreach ($monthsReverse as $key => $month) {
                     if ($key == '12') {
                         $nextmonth = 'Jan';
                     } else {
                         $nextmonth = $arrayMonths[floor(array_search($month, $arrayMonths)) + 1];
                     }
                     $value = $i . '-' . $key;
                     if ($this->_check_for_data($db, $value, 12)) {
                         $html .= '<option value="' . $value . '"';
                         if ($value == $selectedPeriod) {
                             $html .= ' selected="selected"';
                         }
                         $html .= '>' . $nextmonth . ' ';
                         if ($key == 12) {
                             $html .= $i;
                         } else {
                             $html .= $i - 1;
                         }
                         $html .= ' - ' . $month . ' ' . $i . '</option>' . "\n";
                     }
                 }
             }
             break;
         case '1':
         case 'month':
             $option = 'month';
             $period = '1';
             for ($i = $cur_year; $i >= $year_data_start; $i--) {
                 foreach ($monthsReverse as $key => $month) {
                     $value = $i . '-' . $key;
                     if ($this->_check_for_data($db, $value, 1)) {
                         $html .= '<option value="' . $value . '"';
                         if ($value == $selectedPeriod) {
                             $html .= ' selected="selected"';
                         }
                         $html .= '>' . $month . ' ' . $i . '</option>' . "\n";
                     }
                 }
             }
             break;
         case '3':
         case 'qtr':
             $option = 'qtr';
             $period = '3';
             $qtd_found = 0;
             foreach ($monthsReverse as $key => $month) {
                 $value = $cur_year . '-' . $key;
                 if (!$qtd_found && $this->_check_for_data($db, $value, 3)) {
                     $html .= '<option value="' . $value . '"';
                     if ($value == $selectedPeriod) {
                         $html .= ' selected="selected"';
                     }
                     $html .= '>';
                     if ($key <= 3) {
                         $key = 0;
                         $html .= 'Jan';
                     } elseif ($key <= 6) {
                         $key = 3;
                         $html .= 'Apr';
                     } elseif ($key <= 9) {
                         $key = 6;
                         $html .= 'Jul';
                     } else {
                         $key = 9;
                         $html .= 'Oct';
                     }
                     $html .= ' ' . $cur_year . ' - ' . $month . ' ' . $cur_year . '</option>' . "\n";
                     $qtd_found = 1;
                 }
             }
             $qtr_found = 0;
             for ($j = $cur_year; $j >= $year_data_start; $j--) {
                 for ($i = 12; $i > 0; $i = $i - 3) {
                     if ($qtr_found && $key) {
                         $i = $key;
                         $qtd_found = 0;
                     }
                     $value = $j . '-' . sprintf("%02d", $i);
                     if ($this->_check_for_data($db, $value, 3)) {
                         $html .= '<option value="' . $value . '"';
                         if ($value == $selectedPeriod) {
                             $html .= ' selected="selected"';
                         }
                         $html .= '>';
                         if ($i == 3) {
                             $html .= 'Jan';
                         } elseif ($i == 6) {
                             $html .= 'Apr';
                         } elseif ($i == 9) {
                             $html .= 'Jul';
                         } else {
                             $html .= 'Oct';
                         }
                         $html .= ' ' . $j . ' - ';
                         if ($i == 3) {
                             $html .= 'Mar';
                         } elseif ($i == 6) {
                             $html .= 'Jun';
                         } elseif ($i == 9) {
                             $html .= 'Sep';
                         } else {
                             $html .= 'Dec';
                         }
                         $html .= ' ' . $j . '</option>' . "\n";
                     }
                 }
             }
             break;
         case '13':
         case 'fiscal':
             $option = 'fiscal';
             $period = '13';
             $ytd_found = 0;
             $full_year = $cur_year - 1;
             foreach ($monthsReverse as $key => $month) {
                 $value = $cur_year . '-' . $key;
                 if (!$ytd_found && $this->_check_for_data($db, $value, 0)) {
                     $html .= '<option value="' . $value . '"';
                     if ($value == $selectedPeriod) {
                         $html .= ' selected="selected"';
                     }
                     $html .= '>Oct ';
                     if ($cur_month >= 9) {
                         $html .= $cur_year;
                         $full_year = $cur_year;
                     } else {
                         $html .= $cur_year - 1;
                         $full_year = $cur_year - 1;
                     }
                     $html .= ' - ' . $month . ' ' . $cur_year . '</option>' . "\n";
                     $ytd_found = 1;
                 }
             }
             for ($i = $full_year; $i >= $year_data_start; $i--) {
                 $value = $i . '-09';
                 if ($this->_check_for_data($db, $value, 0)) {
                     $html .= '<option value="' . $value . '"';
                     if ($value == $selectedPeriod) {
                         $html .= ' selected="selected"';
                     }
                     $html .= '>Oct ';
                     $html .= $i - 1;
                     $html .= ' - Sep ' . $i . '</option>' . "\n";
                 }
             }
             break;
         case '0':
         case 'year':
             $option = 'year';
             $period = '0';
             $ytd_found = 0;
             foreach ($monthsReverse as $key => $month) {
                 $value = $cur_year . '-' . $key;
                 if (!$ytd_found && $this->_check_for_data($db, $value, 0)) {
                     $html .= '<option value="' . $value . '"';
                     if ($value == $selectedPeriod) {
                         $html .= ' selected="selected"';
                     }
                     $html .= '>Jan - ' . $month . ' ' . $cur_year . '</option>' . "\n";
                     $ytd_found = 1;
                 }
             }
             for ($i = $cur_year - 1; $i >= $year_data_start; $i--) {
                 $value = $i . '-12';
                 if ($this->_check_for_data($db, $value, 0)) {
                     $html .= '<option value="' . $value . '"';
                     if ($value == $selectedPeriod) {
                         $html .= ' selected="selected"';
                     }
                     $html .= '>Jan - Dec ' . $i . '</option>' . "\n";
                 }
             }
             break;
     }
     $html .= '</select></label> <input type="submit" value="' . Lang::txt('PLG_USAGE_VIEW') . '" /></fieldset>' . "\n";
     $html .= '</form>' . "\n";
     $tbl_cnt = 0;
     $html .= '<table summary="' . Lang::txt('A break-down of site visitors.') . '">' . "\n";
     $html .= "\t" . '<caption>' . Lang::txt('Table ' . ++$tbl_cnt . ': User statistics') . '</caption>' . "\n";
     $html .= "\t" . '<thead>' . "\n";
     $html .= "\t\t" . '<tr>' . "\n";
     $html .= "\t\t\t" . '<th scope="col" rowspan="2" colspan="2">' . Lang::txt('Users') . '</th>' . "\n";
     $html .= "\t\t\t" . '<th scope="col" rowspan="2" class="numerical-data">' . Lang::txt('Totals') . '</th>' . "\n";
     $html .= "\t\t\t" . '<th scope="colgroup" colspan="5">' . Lang::txt('Residence') . '</th>' . "\n";
     $html .= "\t\t\t" . '<th scope="colgroup" colspan="5">' . Lang::txt('Organization') . '</th>' . "\n";
     $html .= "\t\t" . '</tr>' . "\n";
     $html .= "\t\t" . '<tr>' . "\n";
     $html .= "\t\t\t" . '<th scope="col" class="numerical-data">' . Lang::txt('Identified') . '</th>' . "\n";
     $html .= "\t\t\t" . '<th scope="col" class="numerical-data">' . Lang::txt('US') . '</th>' . "\n";
     $html .= "\t\t\t" . '<th scope="col" class="numerical-data">' . Lang::txt('Asia') . '</th>' . "\n";
     $html .= "\t\t\t" . '<th scope="col" class="numerical-data">' . Lang::txt('Europe') . '</th>' . "\n";
     $html .= "\t\t\t" . '<th scope="col" class="numerical-data">' . Lang::txt('Other') . '</th>' . "\n";
     $html .= "\t\t\t" . '<th scope="col" class="group numerical-data">' . Lang::txt('Identified') . '</th>' . "\n";
     $html .= "\t\t\t" . '<th scope="col" class="group numerical-data" abbr="' . Lang::txt('Education') . '">' . Lang::txt('Edu.') . '</th>' . "\n";
     $html .= "\t\t\t" . '<th scope="col" class="group numerical-data" abbr="' . Lang::txt('Industry') . '">' . Lang::txt('Ind.') . '</th>' . "\n";
     $html .= "\t\t\t" . '<th scope="col" class="group numerical-data" abbr="' . Lang::txt('Government') . '">' . Lang::txt('Gov.') . '</th>' . "\n";
     $html .= "\t\t\t" . '<th scope="col" class="group numerical-data">' . Lang::txt('Other') . '</th>' . "\n";
     $html .= "\t\t" . '</tr>' . "\n";
     $html .= "\t" . '</thead>' . "\n";
     $html .= "\t" . '<tbody>' . "\n";
     $db->setQuery("SELECT id, label, plot FROM summary_user WHERE id IN (1,2,3,4,5) ORDER BY id");
     $results = $db->loadObjectList();
     if ($results) {
         $i = 0;
         $cls = 'even';
         foreach ($results as $row) {
             $cls = $cls == 'even' ? 'odd' : 'even';
             if ($i == 0) {
                 $cls = 'summary';
             }
             $label = preg_replace('/\\{(.*)\\}/', '<sup><a href="#fn\\1">\\1</a></sup>', $row->label);
             $sparkline = $this->_getSparkline($db, $row->id, $period, $datetime);
             $html .= "\t\t" . '<tr class="' . $cls . '">' . "\n";
             $html .= "\t\t\t" . '<th scope="row">' . trim($label) . '</th>' . "\n";
             if ($row->plot == '1') {
                 $img = $config->get('charts_path') . DS . substr($datetime, 0, 7) . '-' . $period . '-u' . $row->id;
                 if (is_file(PATH_APP . DS . $img . '.gif')) {
                     $html .= "\t\t\t" . '<td><a href="' . $img . '.gif" title="DOM:users1' . $i . '" class="fixedImgTip" rel="external"><img src="' . $img . 'thumb.gif" alt="" /></a><br /><div style="display:none;" id="users1' . $i . '"><img src="' . $img . '.gif" alt="" /></div></td>' . "\n";
                 } else {
                     if (isset($sparkline)) {
                         $html .= "\t\t\t" . '<td>' . $sparkline . '</td>' . "\n";
                     } else {
                         $html .= "\t\t\t" . '<td>&nbsp;</td>' . "\n";
                     }
                 }
             } else {
                 if (isset($sparkline)) {
                     $html .= "\t\t\t" . '<td>' . $sparkline . '</td>' . "\n";
                 } else {
                     $html .= "\t\t\t" . '<td>&nbsp;</td>' . "\n";
                 }
             }
             $html .= $this->_print_user_row($db, $row->id, $period, $datetime);
             $html .= "\t\t" . '</tr>' . "\n";
             $i++;
         }
     } else {
         $html .= "\t\t" . '<tr class="odd">' . "\n";
         $html .= "\t\t\t" . '<td colspan="13" class="textual-data">' . Lang::txt('No data found.') . '</td>' . "\n";
         $html .= "\t\t" . '</tr>' . "\n";
     }
     $html .= "\t" . '</tbody>' . "\n";
     $html .= '</table>' . "\n";
     // Start simulation Usage
     $html .= '<table summary="' . Lang::txt('Simulation Usage') . '">' . "\n";
     $html .= "\t" . '<caption>' . Lang::txt('Table ' . ++$tbl_cnt . ': Simulation Usage') . '</caption>' . "\n";
     $html .= "\t" . '<tbody>' . "\n";
     $db->setQuery("SELECT a.label,b.value,b.valfmt,a.plot,a.id FROM summary_simusage AS a, summary_simusage_vals AS b WHERE a.id=b.rowid AND b.period = '{$period}' AND b.datetime = '{$datetime}' ORDER BY a.id");
     $results = $db->loadObjectList();
     if ($results) {
         $cls = 'even';
         foreach ($results as $row) {
             $cls = $cls == 'even' ? 'odd' : 'even';
             $label = preg_replace('/\\{(.*)\\}/', '<sup><a href="#fn\\1">\\1</a></sup>', $row->label);
             //$sparkline = $this->_getSparkline($db, $row->id, $period, $datetime);
             $html .= "\t\t" . '<tr class="' . $cls . '">' . "\n";
             $html .= "\t\t\t" . '<th scope="row">' . trim($label) . '</th>' . "\n";
             $html .= "\t\t\t" . '<td>' . $this->_fmt_result($row->value, $row->valfmt) . '</td>' . "\n";
             if ($row->plot == '1') {
                 $img = $config->get('charts_path') . DS . substr($datetime, 0, 7) . '-' . $period . '-s' . $row->id;
                 if (is_file(PATH_APP . DS . $img . '.gif')) {
                     $html .= "\t\t\t" . '<td><a href="' . $img . '.gif" title="DOM:sim' . $i . '" class="fixedImgTip" rel="external"><img src="' . $img . 'thumb.gif" alt="" /></a><br /><div style="display:none;" id="sim' . $i . '"><img src="' . $img . '.gif" alt="" /></div></td>' . "\n";
                     //} else if (isset($sparkline)) {
                     //	$html .= "\t\t\t" . '<td>'.$sparkline.'</td>' . "\n";
                 } else {
                     $html .= "\t\t\t" . '<td>&nbsp;</td>' . "\n";
                 }
                 //} else if (isset($sparkline)) {
                 //	$html .= "\t\t\t" . '<td>'.$sparkline.'</td>' . "\n";
             } else {
                 $html .= "\t\t\t" . '<td>&nbsp;</td>' . "\n";
             }
             $html .= "\t\t" . '</tr>' . "\n";
             $i++;
         }
     } else {
         $html .= "\t\t" . '<tr class="odd">' . "\n";
         $html .= "\t\t\t" . '<td colspan="2" class="textual-data">' . Lang::txt('No data found.') . '</td>' . "\n";
         $html .= "\t\t" . '</tr>' . "\n";
     }
     $html .= "\t" . '</tbody>' . "\n";
     $html .= '</table>' . "\n";
     // Start miscellaneous
     $html .= '<table summary="' . Lang::txt('Miscellaneous Statistics') . '">' . "\n";
     $html .= "\t" . '<caption>' . Lang::txt('Table ' . ++$tbl_cnt . ': Miscellaneous Statistics') . '</caption>' . "\n";
     $html .= "\t" . '<tbody>' . "\n";
     $db->setQuery("SELECT a.label,b.value,b.valfmt FROM summary_misc AS a, summary_misc_vals AS b WHERE a.id=b.rowid AND b.period = '{$period}' AND b.datetime = '{$datetime}' ORDER BY a.id");
     $results = $db->loadObjectList();
     if ($results) {
         $cls = 'even';
         foreach ($results as $row) {
             $cls = $cls == 'even' ? 'odd' : 'even';
             //$label = str_replace('{','<sup>',$row->label);
             //$label = str_replace('}','</sup>',$label);
             $label = preg_replace('/\\{(.*)\\}/', '<sup><a href="#fn\\1">\\1</a></sup>', $row->label);
             $html .= "\t\t" . '<tr class="' . $cls . '">' . "\n";
             $html .= "\t\t\t" . '<th scope="row">' . trim($label) . '</th>' . "\n";
             $html .= "\t\t\t" . '<td>' . $this->_fmt_result($row->value, $row->valfmt) . '</td>' . "\n";
             $html .= "\t\t" . '</tr>' . "\n";
         }
     } else {
         $html .= "\t\t" . '<tr class="odd">' . "\n";
         $html .= "\t\t\t" . '<td colspan="2" class="textual-data">' . Lang::txt('No data found.') . '</td>' . "\n";
         $html .= "\t\t" . '</tr>' . "\n";
     }
     $html .= "\t" . '</tbody>' . "\n";
     $html .= '</table>' . "\n";
     /*
     		// "and more" Usage
     		$html .= '<table summary="' . Lang::txt('&quot;and more&quot; Usage') . '">' . "\n";
     		$html .= "\t" . '<caption>' . Lang::txt('Table '.++$tbl_cnt.': &quot;and more&quot; Usage') . '</caption>' . "\n";
     		$html .= "\t" . '<thead>' . "\n";
     		$html .= "\t\t" . '<tr>' . "\n";
     		$html .= "\t\t\t" . '<th scope="col" rowspan="2">' . Lang::txt('Type') . '</th>' . "\n";
     		$html .= "\t\t\t" . '<th scope="colgroup" colspan="2">' . Lang::txt('Users') . '</th>' . "\n";
     		$html .= "\t\t" . '</tr>' . "\n";
     		$html .= "\t\t" . '<tr>' . "\n";
     		$html .= "\t\t\t" . '<th scope="col" class="numerical-data">' . Lang::txt('Interactive') . '</th>' . "\n";
     		$html .= "\t\t\t" . '<th scope="col" class="numerical-data">' . Lang::txt('Download') . '</th>' . "\n";
     		$html .= "\t\t" . '</tr>' . "\n";
     		$html .= "\t" . '</thead>' . "\n";
     		$html .= "\t" . '<tbody>' . "\n";
     		$id = 1;
     		$trows = '';
     		$cls = 'even';
     		while ($id < 9)
     		{
     			$sql = "SELECT a.id, a.label, b.value,b.colid,b.valfmt FROM summary_andmore a, summary_andmore_vals b WHERE a.id=b.rowid AND period='".$period."' AND datetime='".$datetime."' AND a.id='".$id."' ORDER BY b.colid";
     			$db->setQuery($sql);
     			$results = $db->loadObjectList();
     			if ($results) {
     				foreach ($results as $row)
     				{
     					//$label = str_replace('{','<sup>',$row->label);
     					//$label = str_replace('}','</sup>',$label);
     					$label = preg_replace('/\{(.*)\}/','<sup><a href="#fn\\1">\\1</a></sup>',$row->label);
     				$col = $row->colid;
     					if ($col == 1) {
     	               		$value1 = $this->_fmt_result($row->value,$row->valfmt);
     	                } else if ($col == 2) {
     	                	$value2 = $this->_fmt_result($row->value,$row->valfmt);
     	                }
     	            }
     	            $cls = ($cls == 'even') ? 'odd' : 'even';
     			$trows .= "\t\t" . '<tr class="'.$cls.'">' . "\n";
     	            $trows .= "\t\t\t" . '<th scope="row">'.trim($label).'</th>' . "\n";
     	            $trows .= "\t\t\t" . '<td>'.$value1.'</td>' . "\n";
     	            $trows .= "\t\t\t" . '<td>'.$value2.'</td>' . "\n";
     	            $trows .= "\t\t" . '</tr>' . "\n";
     		    }
     		    $id++;
     		}
     		$id = 9;
     		while ($id < 13)
     		{
     			$sql = "SELECT a.id, a.label, b.value,b.colid,b.valfmt FROM summary_andmore a, summary_andmore_vals b WHERE a.id=b.rowid AND period='".$period."' AND datetime='".$datetime."' AND a.id='".$id."' ORDER BY b.colid";
     		    $db->setQuery($sql);
     			$results = $db->loadObjectList();
     			if ($results) {
     				foreach ($results as $row)
     				{
     					//$label = str_replace('{','<sup>',$row->label);
     					//$label = str_replace('}','</sup>',$label);
     					$label = preg_replace('/\{(.*)\}/','<sup><a href="#fn\\1">\\1</a></sup>',$row->label);
     				$col = $row->colid;
     	                if ($col == 1) {
     	                	$value1 = $this->_fmt_result($row->value,$row->valfmt);
     	                } else if ($col == 2) {
     	                	$value2 = $this->_fmt_result($row->value,$row->valfmt);
     	                }
     	            }
     	            $cls = ($cls == 'even') ? 'odd' : 'even';
     			$trows .= "\t\t" . '<tr class="'.$cls.'">' . "\n";
     	            $trows .= "\t\t\t" . '<th scope="row">'.trim($label).'</th>' . "\n";
     	            $trows .= "\t\t\t" . '<td>'.$value1.'</td>' . "\n";
     	            $trows .= "\t\t\t" . '<td>'.$value2.'</td>' . "\n";
     	            $trows .= "\t\t" . '</tr>' . "\n";
     			}
     		    $id++;
     		}
     		if ($trows) {
     			$html .= $trows;
     		} else {
     			$html .= "\t\t" . '<tr class="odd">' . "\n";
     			$html .= "\t\t\t" . '<td colspan="3" class="textual-data">' . Lang::txt('No data found.') . '</td>' . "\n";
     			$html .= "\t\t" . '</tr>' . "\n";
     		}
     		$html .= "\t" . '</tbody>' . "\n";
     		$html .= '</table>' . "\n";
     
     	// Collaboration Usage
     		$html .= '<table summary="' . Lang::txt('Collaboration Usage') . '">' . "\n";
     		$html .= "\t" . '<caption>' . Lang::txt('Table '.++$tbl_cnt.': Collaboration Usage') . '</caption>' . "\n";
     		$html .= "\t" . '<tbody>' . "\n";
     		$sql = "SELECT a.label,b.value,b.valfmt FROM summary_collab AS a, summary_collab_vals AS b WHERE a.id=b.rowid AND b.period = '".$period."' AND b.datetime = '".$datetime."' ORDER BY a.id";
     		$db->setQuery($sql);
     		$results = $db->loadObjectList();
     		if ($results) {
     			$cls = 'even';
     	    	foreach ($results as $row)
     			{
     				$cls = ($cls == 'even') ? 'odd' : 'even';
     			//$label = str_replace('{','<sup>',$row->label);
     				//$label = str_replace('}','</sup>',$label);
     				$label = preg_replace('/\{(.*)\}/','<sup><a href="#fn\\1">\\1</a></sup>',$row->label);
            		$html .= "\t\t" . '<tr class="'.$cls.'">' . "\n";
     	            $html .= "\t\t\t" . '<th scope="row">'.trim($label).'</th>' . "\n";
     	            $html .= "\t\t\t" . '<td>'. $this->_fmt_result($row->value,$row->valfmt) .'</td>' . "\n";
     	            $html .= "\t\t" . '</tr>' . "\n";
     			}
     		} else {
     			$html .= "\t\t" . '<tr class="odd">' . "\n";
     			$html .= "\t\t\t" . '<td colspan="2" class="textual-data">' . Lang::txt('No data found.') . '</td>' . "\n";
     			$html .= "\t\t" . '</tr>' . "\n";
     		}
     		$html .= "\t" . '</tbody>' . "\n";
     		$html .= '</table>' . "\n";
     */
     $html .= '<table summary="' . Lang::txt('User statistics by registered/unregistered') . '">' . "\n";
     $html .= "\t" . '<caption><a name="tot"></a>' . Lang::txt('Table ' . ++$tbl_cnt . ': User statistics by registered/unregistered') . '</caption>' . "\n";
     $html .= "\t" . '<thead>' . "\n";
     $html .= "\t\t" . '<tr>' . "\n";
     $html .= "\t\t\t" . '<th scope="col" rowspan="2" colspan="2">' . Lang::txt('Users') . '</th>' . "\n";
     $html .= "\t\t\t" . '<th scope="col" rowspan="2" class="numerical-data">' . Lang::txt('Totals') . '</th>' . "\n";
     $html .= "\t\t\t" . '<th scope="colgroup" colspan="5">' . Lang::txt('Residence') . '</th>' . "\n";
     $html .= "\t\t\t" . '<th scope="colgroup" colspan="5">' . Lang::txt('Organization') . '</th>' . "\n";
     $html .= "\t\t" . '</tr>' . "\n";
     $html .= "\t\t" . '<tr>' . "\n";
     $html .= "\t\t\t" . '<th scope="col" class="numerical-data">' . Lang::txt('Identified') . '</th>' . "\n";
     $html .= "\t\t\t" . '<th scope="col" class="numerical-data">' . Lang::txt('US') . '</th>' . "\n";
     $html .= "\t\t\t" . '<th scope="col" class="numerical-data">' . Lang::txt('Asia') . '</th>' . "\n";
     $html .= "\t\t\t" . '<th scope="col" class="numerical-data">' . Lang::txt('Europe') . '</th>' . "\n";
     $html .= "\t\t\t" . '<th scope="col" class="numerical-data">' . Lang::txt('Other') . '</th>' . "\n";
     $html .= "\t\t\t" . '<th scope="col" class="group numerical-data">' . Lang::txt('Identified') . '</th>' . "\n";
     $html .= "\t\t\t" . '<th scope="col" class="group numerical-data" abbr="' . Lang::txt('Education') . '">' . Lang::txt('Edu.') . '</th>' . "\n";
     $html .= "\t\t\t" . '<th scope="col" class="group numerical-data" abbr="' . Lang::txt('Industry') . '">' . Lang::txt('Ind.') . '</th>' . "\n";
     $html .= "\t\t\t" . '<th scope="col" class="group numerical-data" abbr="' . Lang::txt('Government') . '">' . Lang::txt('Gov.') . '</th>' . "\n";
     $html .= "\t\t\t" . '<th scope="col" class="group numerical-data">' . Lang::txt('Other') . '</th>' . "\n";
     $html .= "\t\t" . '</tr>' . "\n";
     $html .= "\t" . '</thead>' . "\n";
     $html .= "\t" . '<tbody>' . "\n";
     $db->setQuery("SELECT id, label, plot FROM summary_user WHERE id IN (1,6,7,8) ORDER BY id");
     $results = $db->loadObjectList();
     if ($results) {
         $i = 5;
         $cls = 'even';
         foreach ($results as $row) {
             //$label = str_replace('{','<sup>',$row->label);
             //$label = str_replace('}','</sup>',$label);
             $label = preg_replace('/\\{(.*)\\}/', '<sup><a href="#fn\\1">\\1</a></sup>', $row->label);
             $cls = $cls == 'even' ? 'odd' : 'even';
             if ($i == 5) {
                 $cls = 'summary';
             }
             $sparkline = $this->_getSparkline($db, $row->id, $period, $datetime);
             $html .= "\t\t" . '<tr class="' . $cls . '">' . "\n";
             $html .= "\t\t\t" . '<th scope="row">' . trim($label) . '</th>' . "\n";
             if ($row->plot == '1') {
                 $img = $config->get('charts_path') . DS . substr($datetime, 0, 7) . '-' . $period . '-u' . $row->id;
                 if (is_file(PATH_APP . DS . $img . '.gif')) {
                     $html .= "\t\t\t" . '<td><a href="' . $img . '.gif" title="DOM:users2' . $i . '" class="fixedImgTip" rel="external"><img src="' . $img . 'thumb.gif" alt="" /></a><br /><div style="display:none;" id="users2' . $i . '"><img src="' . $img . '.gif" alt="" /></div></td>' . "\n";
                 } else {
                     if (isset($sparkline)) {
                         $html .= "\t\t\t" . '<td>' . $sparkline . '</td>' . "\n";
                     } else {
                         $html .= "\t\t\t" . '<td>&nbsp;</td>' . "\n";
                     }
                 }
             } else {
                 if (isset($sparkline)) {
                     $html .= "\t\t\t" . '<td>' . $sparkline . '</td>' . "\n";
                 } else {
                     $html .= "\t\t\t" . '<td>&nbsp;</td>';
                 }
             }
             $html .= $this->_print_user_row($db, $row->id, $period, $datetime);
             $html .= "\t\t" . '</tr>' . "\n";
             $i++;
         }
     } else {
         $html .= "\t\t" . '<tr class="odd">' . "\n";
         $html .= "\t\t\t" . '<td colspan="13" class="textual-data">' . Lang::txt('No data found.') . '</td>' . "\n";
         $html .= "\t\t" . '</tr>' . "\n";
     }
     $html .= "\t" . '</tbody>' . "\n";
     $html .= '</table>' . "\n";
     $html .= '<div class="footnotes">' . "\n";
     $html .= "\t" . '<hr />' . "\n";
     $html .= "\t" . '<ol>' . "\n";
     $html .= "\t\t" . '<li id="fn1"><a name="fn1"></a>Sum of Registered Users<sup><a href="#fn2">2</a></sup>, Unregistered Interactive Users<sup><a href="#fn3">3</a></sup> and Unregistered Download Users<sup><a href="#fn4">4</a></sup></li>' . "\n";
     $html .= "\t\t" . '<li id="fn2"><a name="fn2"></a>Number of Users that logged in. User registration assigns a unique login to each individual user.</li>' . "\n";
     $html .= "\t\t" . '<li id="fn3"><a name="fn3"></a>Number of Unregistered Users, identified by unique hosts/IPs, that had an active Session <sup><a href="#fn10">10</a></sup> without logging in. Does not include known web bots/crawlers.</li>' . "\n";
     $html .= "\t\t" . '<li id="fn4"><a name="fn4"></a>Number of Unregistered users, identified by unique hosts/IPs, that had an active session of less than 15 minutes without logging in and downloaded a non-interactive resource such as PDF or podcast. Does not include web bots/crawlers.</li>' . "\n";
     $html .= "\t\t" . '<li id="fn5"><a name="fn5"></a>Number of Registered Users<sup><a href="#fn2">2</a></sup> that ran one or more simulation runs.</li>' . "\n";
     $html .= "\t\t" . '<li id="fn6"><a name="fn6"></a>All Unregistered Users, identified by unique hosts/IPs, that had an active Session <sup><a href="#fn10">10</a></sup>. Does not include known web bots/crawlers.</li>' . "\n";
     $html .= "\t\t" . '<li id="fn7"><a name="fn7"></a>All Unregistered users, identified by unique hosts/IPs that downloaded a non-interactive resource such as PDF or podcast. Does not include known web bots/crawlers.</li>' . "\n";
     $html .= "\t\t" . '<li id="fn8"><a name="fn8"></a>Sum of Simulation Users <sup><a href="#fn5">5</a></sup> + Unregistered Interactive Users <sup><a href="#fn3">3</a></sup> including web bots/crawlers.</li>' . "\n";
     $html .= "\t\t" . '<li id="fn9"><a name="fn9"></a>Number of Simulation users that returned after a gap of 3 months.</li>' . "\n";
     $html .= "\t\t" . '<li id="fn10"><a name="fn10"></a>Begins when an IP is active on the site for at least 15 minutes. Ends when inactive for more than 30 minutes, including time spent viewing videos.</li>' . "\n";
     $html .= "\t\t" . '<li id="fn11"><a name="fn11"></a>Identified by a unique IP address / hostname.</li>' . "\n";
     $html .= "\t\t" . '<li id="fn12"><a name="fn12"></a>Based on MIT OCW metric of Visits: A visit is activity by a unique visitor delimitated by a 30 minute absence from the site on either side of the activity.<br />These visits correspond to unique visitors <sup><a href="#fn11">11</a></sup>. Does not include known web bots/crawlers</li>' . "\n";
     $html .= "\t\t" . '<li id="fn13"><a name="fn13"></a>Number of Simulation sessions that were shared between 2 or more users.</li>' . "\n";
     $html .= "\t" . '</ol>' . "\n";
     $html .= '</div><!-- / .footnotes -->' . "\n";
     return $html;
 }
Example #25
0
 /**
  * Gets top cited tools
  *
  * @param      object $database JDatabase
  * @return     string HTML
  */
 private function gettopcited_tools($database)
 {
     $html = '';
     $sql = 'SELECT COUNT(DISTINCT c.id) FROM `#__resources` r, `#__citations` c, `#__citations_assoc` ca WHERE r.id = ca.oid AND ca.cid = c.id AND ca.tbl = "resource" AND r.type = "7" AND r.standalone = "1" AND c.published = "1"';
     $database->setQuery($sql);
     $result = $database->loadResult();
     $html .= "\t" . '<thead>' . "\n";
     $html .= "\t\t" . '<tr>' . "\n";
     $html .= "\t\t\t" . '<th class="numerical-data">' . Lang::txt('#') . '</th>' . "\n";
     $html .= "\t\t\t" . '<th>' . Lang::txt('Tool') . '</th>' . "\n";
     $html .= "\t\t\t" . '<th class="numerical-data">' . Lang::txt('Citations') . '</th>' . "\n";
     $html .= "\t\t" . '</tr>' . "\n";
     $html .= "\t" . '</thead>' . "\n";
     if ($result) {
         $html .= "\t" . '<tfoot>' . "\n";
         $html .= "\t\t" . '<tr class="summary">' . "\n";
         $html .= "\t\t\t" . '<th colspan="2" class="numerical-data">' . Lang::txt('Total Tools Citations') . '</th>' . "\n";
         $html .= "\t\t\t" . '<td class="numerical-data">' . $result . '</td>' . "\n";
         $html .= "\t\t" . '</tr>' . "\n";
         $html .= "\t" . '</tfoot>' . "\n";
     }
     $count = 1;
     $sql = 'SELECT DISTINCT r.id, r.title, r.published, COUNT(c.id) AS citations FROM `#__resources` r, `#__citations` c, `#__citations_assoc` ca WHERE r.id = ca.oid AND ca.cid = c.id AND ca.tbl = "resource" AND r.type = "7" AND r.standalone = "1" AND c.published = "1" GROUP BY r.id ORDER BY citations DESC';
     $database->setQuery($sql);
     $results = $database->loadObjectList();
     if ($results) {
         $cls = 'even';
         $html .= "\t" . '<tbody>' . "\n";
         foreach ($results as $row) {
             $cls = $cls == 'even' ? 'odd' : 'even';
             if ($row->citations == 0) {
                 continue;
             }
             if ($row->published == "1") {
                 $html .= "\t\t" . '<tr class="' . $cls . '">' . "\n";
                 $html .= "\t\t\t" . '<td>' . $count . '</td>' . "\n";
                 $html .= "\t\t\t" . '<td class="textual-data"><a href="' . Route::url('index.php?option=com_resources&id=' . $row->id . '&active=usage') . '">' . stripslashes($row->title) . '</a></td>';
                 $html .= "\t\t\t" . '<td>' . $row->citations . '</td>' . "\n";
                 $html .= "\t\t" . '</tr>' . "\n";
             } else {
                 $html .= "\t\t" . '<tr class="' . $cls . '">' . "\n";
                 $html .= "\t\t\t" . '<td>' . $count . '</td>' . "\n";
                 $html .= "\t\t\t" . '<td class="textual-data">' . stripslashes($row->title) . '</td>';
                 $html .= "\t\t\t" . '<td>' . $row->citations . '</td>' . "\n";
                 $html .= "\t\t" . '</tr>' . "\n";
             }
             $count++;
         }
         $html .= "\t" . '</tbody>' . "\n";
     }
     if ($count == 1) {
         $html = "\t" . 'No Data Available to Display' . "\n";
     }
     return $html;
 }
Example #26
0
 /**
  * Get a count of standalone children
  *
  * @param      array $filters Optional filters to apply
  * @return     integer
  */
 public function getStandaloneCount($filters)
 {
     $sql = "SELECT COUNT(*)" . " FROM #__resource_types AS rt, #__resources AS r" . " JOIN #__resource_assoc AS a ON r.id=a.child_id" . " LEFT JOIN #__resource_types AS t ON r.logical_type=t.id" . " WHERE r.published=1 AND a.parent_id=" . $filters['id'] . " AND r.standalone=1 AND r.type=rt.id";
     $this->_db->setQuery($sql);
     return $this->_db->loadResult();
 }
Example #27
0
 /**
  * List records
  *
  * @param   string  $from   Timestamp
  * @param   string  $until  Timestamp
  * @param   string  $set    Set to filter by
  * @param   string  $verb
  * @return  object  $this
  */
 public function records($from, $until, $set = null, $verb = 'ListRecords')
 {
     // Set flow control vars
     $limit = $this->get('limit', 50);
     $start = $this->get('start', 0);
     $queries = array();
     foreach ($this->providers as $provider) {
         if (!($query = $provider->records(array('from' => $from, 'until' => $until, 'set' => $set)))) {
             continue;
         }
         $queries[] = $query;
     }
     if (!count($queries)) {
         return $this->error(self::ERROR_RECORD_NOT_FOUND, null, $verb);
     }
     // Get Records
     $sql = "SELECT COUNT(*) FROM (" . implode(' UNION ', $queries) . ") AS m";
     $this->database->setQuery($sql);
     $total = $this->database->loadResult();
     $sql = "SELECT m.* FROM (" . implode(' UNION ', $queries) . ") AS m LIMIT " . $start . "," . $limit;
     $this->database->setQuery($sql);
     $records = $this->database->loadObjectList();
     if (!count($records)) {
         return $this->error(self::ERROR_RECORD_NOT_FOUND, null, $verb);
     }
     // Hook for post processing
     foreach ($this->providers as $provider) {
         $records = $provider->postRecords($records);
     }
     // Write schema
     $this->response->element('request', $this->get('baseURL') . '/oaipmh')->attr('verb', $verb)->end()->element($verb);
     $this->schema->records($records, $verb == 'ListIdentifiers' ? false : true);
     // Write resumption token if needed
     if ($total > $start + $limit) {
         $resumption = $this->encodeToken($limit, $start, $from, $until, $set, $this->get('metadataPrefix'));
         $this->response->element('resumptionToken', $resumption)->attr('completeListSize', $total)->attr('cursor', $start + $limit)->end();
     }
     $this->response->end();
     return $this;
 }
Example #28
0
 /**
  * Checks required database tables for migration
  *
  * @param   array   $tables Array of database tables to search for
  * @return  boolean True if all tables are existent, false otherwise
  * @since   1.5.0
  */
 protected function checkTables($tables = array())
 {
     $displayData = new stdClass();
     $displayData->title = JText::_('COM_JOOMGALLERY_MIGMAN_DATABASETABLES');
     $ready = false;
     if (!$this->otherDatabase || is_null($this->_db2)) {
         $db = $this->_db;
     } else {
         $db = $this->_db2;
     }
     $displayData->checks = array();
     foreach ($tables as $table) {
         $check = array();
         try {
             $query = $db->getQuery(true)->select('COUNT(*)')->from($table);
             $db->setQuery($query);
             $count = $db->loadResult();
             if ($count == 0) {
                 $check['title'] = $table . ': <span style="color:#080; font-size:12px; font-weight:bold;">' . JText::_('COM_JOOMGALLERY_MIGMAN_EMPTY') . '</span>';
                 $check['state'] = true;
             } else {
                 $check['title'] = $table . ': <span style="color:#080; font-weight:bold;">' . $count . ' ' . JText::_('COM_JOOMGALLERY_MIGMAN_ROWS') . '</span>';
                 $check['state'] = true;
                 $ready = true;
             }
         } catch (Exception $e) {
             $check['title'] = $table . ': <span style="color:#f30; font-weight:bold;">' . $db->getErrorMsg() . '</span>';
             $check['state'] = false;
         }
         $displayData->checks[] = $check;
     }
     // Check JoomGallery tables
     $tables = array(_JOOM_TABLE_IMAGES, _JOOM_TABLE_CATEGORIES, _JOOM_TABLE_COMMENTS, _JOOM_TABLE_NAMESHIELDS, _JOOM_TABLE_USERS, _JOOM_TABLE_VOTES, _JOOM_TABLE_IMAGE_DETAILS, _JOOM_TABLE_CATEGORY_DETAILS);
     $prefix = $this->_mainframe->getCfg('dbprefix');
     foreach ($tables as $table) {
         $check = array();
         if ($table != _JOOM_TABLE_CATEGORIES) {
             $query = $this->_db->getQuery(true)->select('COUNT(*)')->from($this->_db->qn($table));
         } else {
             $query = $this->_db->getQuery(true)->select('COUNT(*)')->from($this->_db->qn(_JOOM_TABLE_CATEGORIES))->where('cid != 1');
         }
         $this->_db->setQuery($query);
         $count = $this->_db->loadResult();
         if (!is_null($count) && $count == 0) {
             $check['title'] = str_replace('#__', $prefix, $table) . ': <span style="color:#080; font-size:12px; font-weight:bold;">' . JText::_('COM_JOOMGALLERY_MIGMAN_EMPTY') . '</span>';
             $check['state'] = true;
         } else {
             $check['title'] = str_replace('#__', $prefix, $table) . ': <span style="color:#f30; font-weight:bold;">' . $count . ' ' . JText::_('COM_JOOMGALLERY_MIGMAN_ROWS') . '. ';
             $check['title'] .= JText::_('COM_JOOMGALLERY_MIGMAN_ONLY_IN_NEW_INSTALLATION') . '</span> ' . JText::_('COM_JOOMGALLERY_MIGMAN_PLEASE_REINSTALL');
             $check['state'] = false;
             $ready = false;
         }
         $displayData->checks[] = $check;
     }
     // Check whether ROOT category exists
     $check = array();
     $query = $this->_db->getQuery(true)->select('COUNT(*)')->from($this->_db->qn(_JOOM_TABLE_CATEGORIES))->where('cid = 1')->where('name = ' . $this->_db->q('ROOT'))->where('parent_id = 0');
     $this->_db->setQuery($query);
     if ($this->_db->loadResult()) {
         $check['title'] = JText::_('COM_JOOMGALLERY_MIGMAN_ROOT_CATEGORY_EXISTS');
         $check['state'] = true;
     } else {
         $check['title'] = '<span style="color:#f30; font-weight:bold;">' . JText::_('COM_JOOMGALLERY_MIGMAN_ROOT_CATEGORY_DOES_NOT_EXIST') . '</span> ' . JText::_('COM_JOOMGALLERY_MIGMAN_PLEASE_REINSTALL');
         $check['state'] = false;
         $ready = false;
     }
     $displayData->checks[] = $check;
     // Check whether ROOT asset exists
     $check = array();
     $query = $this->_db->getQuery(true)->select('COUNT(*)')->from($this->_db->qn('#__assets'))->where('name = ' . $this->_db->q(_JOOM_OPTION))->where('parent_id = 1');
     $this->_db->setQuery($query);
     if ($this->_db->loadResult()) {
         $check['title'] = JText::_('COM_JOOMGALLERY_MIGMAN_ROOT_ASSET_EXISTS');
         $check['state'] = true;
     } else {
         $check['title'] = '<span style="color:#f30; font-weight:bold;">' . Text::_('COM_JOOMGALLERY_MIGMAN_ROOT_ASSET_DOES_NOT_EXIST') . '</span> ' . JText::_('COM_JOOMGALLERY_MIGMAN_PLEASE_REINSTALL');
         $check['state'] = false;
         $ready = false;
     }
     $displayData->checks[] = $check;
     $layout = new JLayoutFile('joomgallery.migration.checksection', JPATH_COMPONENT . '/layouts');
     echo $layout->render($displayData);
     return $ready;
 }
Example #29
0
 /**
  * Method to get the page title of any menu item that is linked to the
  * content item, if it exists and is set.
  *
  * @param   string  $url  The url of the item.
  *
  * @return  mixed  The title on success, null if not found.
  *
  * @since   2.5
  * @throws  Exception on database error.
  */
 protected function getItemMenuTitle($url)
 {
     $return = null;
     // Set variables
     $user = JFactory::getUser();
     $groups = implode(',', $user->getAuthorisedViewLevels());
     // Build a query to get the menu params.
     $query = $this->db->getQuery(true)->select($this->db->quoteName('params'))->from($this->db->quoteName('#__menu'))->where($this->db->quoteName('link') . ' = ' . $this->db->quote($url))->where($this->db->quoteName('published') . ' = 1')->where($this->db->quoteName('access') . ' IN (' . $groups . ')');
     // Get the menu params from the database.
     $this->db->setQuery($query);
     $params = $this->db->loadResult();
     // Check the results.
     if (empty($params)) {
         return $return;
     }
     // Instantiate the params.
     $params = json_decode($params);
     // Get the page title if it is set.
     if ($params->page_title) {
         $return = $params->page_title;
     }
     return $return;
 }
Example #30
0
 /**
  * Returns the number of images of the current user
  *
  * @return  int     The number of images of the current user
  * @since   1.5.5
  */
 protected function getImageNumber()
 {
     $query = $this->_db->getQuery(true)->select('COUNT(id)')->from(_JOOM_TABLE_IMAGES)->where('owner = ' . $this->_user->get('id'));
     $timespan = $this->_config->get('jg_maxuserimage_timespan');
     if ($timespan > 0) {
         $query->where('imgdate > (UTC_TIMESTAMP() - INTERVAL ' . $timespan . ' DAY)');
     }
     $this->_db->setQuery($query);
     return $this->_db->loadResult();
 }