/** * Return the Administration Tool Application modules the administrator has access to * * @param int $id The ID of the administrator * @access public * @return array */ public static function getUserLevels($id, $site = null) { if (empty($site)) { $site = OSCOM::getSite(); } $data = array('id' => $id); $applications = array(); foreach (OSCOM::callDB('GetAccessUserLevels', $data, 'Core') as $am) { $applications[] = $am['module']; } if (in_array('*', $applications)) { $applications = array(); $DLapps = new DirectoryListing(OSCOM::BASE_DIRECTORY . 'Core/Site/' . $site . '/Application'); $DLapps->setIncludeFiles(false); foreach ($DLapps->getFiles() as $file) { if (preg_match('/[A-Z]/', substr($file['name'], 0, 1)) && !in_array($file['name'], call_user_func(array('osCommerce\\OM\\Core\\Site\\' . $site . '\\Controller', 'getGuestApplications'))) && file_exists($DLapps->getDirectory() . '/' . $file['name'] . '/Controller.php')) { // HPDL remove preg_match $applications[] = $file['name']; } } $DLcapps = new DirectoryListing(OSCOM::BASE_DIRECTORY . 'Custom/Site/' . $site . '/Application'); $DLcapps->setIncludeFiles(false); foreach ($DLcapps->getFiles() as $file) { if (!in_array($file['name'], $applications) && !in_array($file['name'], call_user_func(array('osCommerce\\OM\\Core\\Site\\' . $site . '\\Controller', 'getGuestApplications'))) && file_exists($DLcapps->getDirectory() . '/' . $file['name'] . '/Controller.php')) { $applications[] = $file['name']; } } } $shortcuts = array(); foreach (OSCOM::callDB('GetAccessUserShortcuts', $data, 'Core') as $as) { $shortcuts[] = $as['module']; } $levels = array(); foreach ($applications as $app) { $application_class = 'osCommerce\\OM\\Core\\Site\\' . $site . '\\Application\\' . $app . '\\Controller'; if (class_exists($application_class)) { if (Registry::exists('Application') && $app == OSCOM::getSiteApplication()) { $OSCOM_Application = Registry::get('Application'); } else { Registry::get('Language')->loadIniFile($app . '.php'); $OSCOM_Application = new $application_class(false); } $levels[$app] = array('module' => $app, 'icon' => $OSCOM_Application->getIcon(), 'title' => $OSCOM_Application->getTitle(), 'group' => $OSCOM_Application->getGroup(), 'linkable' => $OSCOM_Application->canLinkTo(), 'shortcut' => in_array($app, $shortcuts), 'sort_order' => $OSCOM_Application->getSortOrder()); } } return $levels; }
/** * Return the Administration Tool Application modules the administrator has access to * * @param int $id The ID of the administrator * @access public * @return array */ public static function getUserLevels($id, $site = null) { $OSCOM_Database = Registry::get('Database'); if (empty($site)) { $site = OSCOM::getSite(); } $applications = array(); $Qaccess = $OSCOM_Database->query('select module from :table_administrators_access where administrators_id = :administrators_id'); $Qaccess->bindInt(':administrators_id', $id); $Qaccess->execute(); while ($Qaccess->next()) { $applications[] = $Qaccess->value('module'); } if (in_array('*', $applications)) { $applications = array(); $DLapps = new DirectoryListing(OSCOM::BASE_DIRECTORY . 'Core/Site/' . $site . '/Application'); $DLapps->setIncludeFiles(false); foreach ($DLapps->getFiles() as $file) { if (preg_match('/[A-Z]/', substr($file['name'], 0, 1)) && !in_array($file['name'], call_user_func(array('osCommerce\\OM\\Core\\Site\\' . $site . '\\Controller', 'getGuestApplications'))) && file_exists($DLapps->getDirectory() . '/' . $file['name'] . '/Controller.php')) { // HPDL remove preg_match $applications[] = $file['name']; } } } $shortcuts = array(); $Qshortcuts = $OSCOM_Database->query('select module from :table_administrator_shortcuts where administrators_id = :administrators_id'); $Qshortcuts->bindInt(':administrators_id', $id); $Qshortcuts->execute(); while ($Qshortcuts->next()) { $shortcuts[] = $Qshortcuts->value('module'); } $levels = array(); foreach ($applications as $app) { $application_class = 'osCommerce\\OM\\Core\\Site\\' . $site . '\\Application\\' . $app . '\\Controller'; if (class_exists($application_class)) { if (Registry::exists('Application') && $app == OSCOM::getSiteApplication()) { $OSCOM_Application = Registry::get('Application'); } else { Registry::get('Language')->loadIniFile($app . '.php'); $OSCOM_Application = new $application_class(false); } $levels[$app] = array('module' => $app, 'icon' => $OSCOM_Application->getIcon(), 'title' => $OSCOM_Application->getTitle(), 'group' => $OSCOM_Application->getGroup(), 'linkable' => $OSCOM_Application->canLinkTo(), 'shortcut' => in_array($app, $shortcuts), 'sort_order' => $OSCOM_Application->getSortOrder()); } } return $levels; }
/** * Read the Phar package contents * * @param array $key The version to read * @access public * @return mixed */ public static function getPackageContents() { $result = array('entries' => array()); $phar_can_open = true; try { $phar = new Phar(DIR_FS_WORK . 'updates/update.phar'); } catch (Exception $e) { $phar_can_open = false; trigger_error($e->getMessage()); } if ($phar_can_open === true) { $update_pkg = array(); foreach (new RecursiveIteratorIterator($phar) as $iteration) { if (($pos = strpos($iteration->getPathName(), 'update.phar')) !== false) { $update_pkg[] = substr($iteration->getPathName(), $pos + 12); } } natcasesort($update_pkg); $counter = 0; foreach ($update_pkg as $file) { $custom = false; // update the path with admin config value to account for a different admin/ dir $file = str_replace('admin/', DIR_WS_ADMIN, $file); $result['entries'][] = array('key' => $counter, 'name' => $file, 'exists' => file_exists(realpath(DIR_FS_CATALOG) . '/' . $file), 'writable' => self::isWritable(realpath(DIR_FS_CATALOG) . '/' . $file) && self::isWritable(realpath(DIR_FS_CATALOG) . '/' . dirname($file)), 'custom' => $custom, 'to_delete' => false); $counter++; } } $meta = $phar->getMetadata(); if (isset($meta['delete'])) { $files = array(); if (is_array($meta['delete']) && count($meta['delete']) > 0) { foreach ($meta['delete'] as $file) { // update the path with admin config value to account for a different admin/ dir $file = str_replace('admin/', DIR_WS_ADMIN, $file); if (file_exists(realpath(DIR_FS_CATALOG) . '/' . $file)) { if (is_dir(realpath(DIR_FS_CATALOG) . '/' . $file)) { $DL = new DirectoryListing(realpath(DIR_FS_CATALOG) . '/' . $file); $DL->setRecursive(true); $DL->setAddDirectoryToFilename(true); $DL->setIncludeDirectories(false); foreach ($DL->getFiles() as $f) { $files[] = $file . '/' . $f['name']; } } else { $files[] = $file; } } } } natcasesort($files); foreach ($files as $d) { $writable = false; $custom = false; $writable = self::isWritable(realpath(DIR_FS_CATALOG) . '/' . $d) && self::isWritable(realpath(DIR_FS_CATALOG) . '/' . dirname($d)); $result['entries'][] = array('key' => $counter, 'name' => $d, 'exists' => true, 'writable' => $writable, 'custom' => $custom, 'to_delete' => true); $counter++; } } $result['total'] = count($result['entries']); return $result; }