Ejemplo n.º 1
0
 /**
  * Class constructor
  *
  * @param string $accountId If null, the current account ID is used
  * @param string $accountType If null, the current account type is used
  * @return OA_Central_M2M
  */
 function OA_Central_M2M($accountId = null)
 {
     parent::OA_Central_Common();
     $currentId = OA_Permission::getAccountId();
     if (is_null($accountId)) {
         $this->accountId = $currentId;
     } else {
         $this->accountId = $accountId;
     }
     if ($this->accountId == $currentId) {
         $this->accountType = OA_Permission::getAccountType();
     } else {
         $doAccounts = OA_Dal::factoryDO('accounts');
         $doAccounts->account_id = $this->accountId;
         $doAccounts->find();
         if ($doAccounts->fetch()) {
             $this->accountType = $doAccounts->account_type;
         } else {
             Max::raiseError('Unexisting account ID', null, PEAR_ERROR_DIE);
         }
     }
     if ($this->accountType == OA_ACCOUNT_ADMIN) {
         $this->accountId = 0;
     }
 }
Ejemplo n.º 2
0
 /**
  * The method to generate a plugin-style report XLS from an already
  * prepared statistics page OA_Admin_Statistics_Common object.
  */
 function export()
 {
     // Prepare the report name
     // Get system navigation
     $oMenu = OA_Admin_Menu::singleton();
     // Get section by pageId
     $oCurrentSection = $oMenu->get($this->oStatsController->pageId);
     if ($oCurrentSection == null) {
         phpAds_Die($GLOBALS['strErrorOccurred'], 'Menu system error: <strong>' . OA_Permission::getAccountType(true) . '::' . htmlspecialchars($ID) . '</strong> not found for the current user');
     }
     // Get name
     $reportName = $oCurrentSection->getName();
     $this->_name = $reportName;
     // Prepare the output writer for generation
     $reportFileName = 'Exported Statistics - ' . $reportName;
     if (!empty($this->oStatsController->aDates['day_begin'])) {
         $oStartDate = new Date($this->oStatsController->aDates['day_begin']);
         $reportFileName .= ' from ' . $oStartDate->format($GLOBALS['date_format']);
     }
     if (!empty($this->oStatsController->aDates['day_end'])) {
         $oEndDate = new Date($this->oStatsController->aDates['day_end']);
         $reportFileName .= ' to ' . $oEndDate->format($GLOBALS['date_format']);
     }
     $reportFileName .= '.xls';
     $this->_oReportWriter->openWithFilename($reportFileName);
     // Get the header and data arrays from the same statistics controllers
     // that prepare stats for the user interface stats pages
     list($aHeaders, $aData) = $this->getHeadersAndDataFromStatsController(null, $this->oStatsController);
     // Add the worksheet
     $name = ucfirst($this->oStatsController->entity) . ' ' . ucfirst($this->oStatsController->breakdown);
     $this->createSubReport($reportName, $aHeaders, $aData);
     // Close the report writer and send the report to the user
     $this->_oReportWriter->closeAndSend();
 }
 /**
  * A private method to return the account ID of the
  * account that should "own" audit trail entries for
  * this entity type; NOT related to the account ID
  * of the currently active account performing an
  * action.
  *
  * @return integer The account ID to insert into the
  *                 "account_id" column of the audit trail
  *                 database table.
  */
 public function getOwningAccountIds($resetCache = false)
 {
     $accountType = OA_Permission::getAccountType(false);
     switch ($accountType) {
         case OA_ACCOUNT_ADMIN:
             return parent::_getOwningAccountIdsByAccountId($accountId = OA_Permission::getAccountId());
         case OA_ACCOUNT_ADVERTISER:
             $parentTable = 'clients';
             $parentKeyName = 'clientid';
             break;
         case OA_ACCOUNT_TRAFFICKER:
             $parentTable = 'affiliates';
             $parentKeyName = 'affiliateid';
             break;
         case OA_ACCOUNT_MANAGER:
             $parentTable = 'agency';
             $parentKeyName = 'agencyid';
             break;
     }
     return $this->_getOwningAccountIds($parentTable, $parentKeyName);
 }
Ejemplo n.º 4
0
 /**
  * Returns the instance of menu. Subsequent calls return the same object.
  *
  * @return OA_Admin_Menu
  */
 function &singleton()
 {
     $accountType = OA_Permission::getAccountType();
     if (isset($GLOBALS['_MAX']['MENU_OBJECT'][$accountType])) {
         $oMenu =& $GLOBALS['_MAX']['MENU_OBJECT'][$accountType];
     } elseif ($GLOBALS['_MAX']['CONF']['debug']['production'] != 0 && ($oMenu = OA_Admin_Menu::_loadFromCache($accountType))) {
         $GLOBALS['_MAX']['MENU_OBJECT'][$accountType] =& $oMenu;
     } else {
         $oMenu = new OA_Admin_Menu();
         if (empty($oMenu->aAllSections)) {
             include_once MAX_PATH . '/lib/OA/Admin/Menu/config.php';
             $oMenu = _buildNavigation(OA_Permission::getAccountType());
         }
         require_once LIB_PATH . '/Plugin/ComponentGroupManager.php';
         $oPluginManager = new OX_Plugin_ComponentGroupManager();
         $oPluginManager->mergeMenu($oMenu, $accountType);
         $GLOBALS['_MAX']['MENU_OBJECT'][$accountType] =& $oMenu;
         $oMenu->_saveToCache($accountType);
     }
     // Filter against user-account-preferences...
     return $oMenu;
 }
Ejemplo n.º 5
0
 /**
  * A method to disable all of the supplied columns from being displayed
  * by *any* user in the system, should they have set those columns to
  * be displayed.
  *
  * Can only be called by the admin account.
  *
  * @param array $aColumns An array of the "primary" statistics column
  *                        names (i.e. less the "_label" and "_rank" suffixes)
  *                        that need to be disabled.
  */
 function disableStatisticsColumns($aColumns)
 {
     // Ensure that this method is only ever called by the admin account
     $currentAccountType = OA_Permission::getAccountType();
     if ($currentAccountType != OA_ACCOUNT_ADMIN) {
         return;
     }
     // Disable the required columns
     foreach ($aColumns as $preference) {
         // Obtain the preference ID value for the column
         $doPreferences = OA_Dal::factoryDO('preferences');
         $doPreferences->preference_name = $preference;
         $doPreferences->find();
         if ($doPreferences->getRowCount() != 1) {
             // Could not locate the statistics column in the preferences
             // table, so suspect that it does not exist, go to next column
             continue;
         }
         $doPreferences->fetch();
         $aColumnPreference = $doPreferences->toArray();
         $columnPreferenceId = $aColumnPreference['preference_id'];
         // Update any instances of this preference ID so that
         // the column is disabled, but without making any other
         // changes to custom rank values or column names
         $doAccount_preference_assoc = OA_Dal::factoryDO('account_preference_assoc');
         $doAccount_preference_assoc->preference_id = $columnPreferenceId;
         $doAccount_preference_assoc->find();
         while ($doAccount_preference_assoc->fetch()) {
             $doAccount_preference_assoc->value = 0;
             $doAccount_preference_assoc->update();
         }
     }
 }
Ejemplo n.º 6
0
 *
 * Results of auto completion are limited to those users that are already
 * linked to accounts in the current account realm.
 */
$q = strtolower($_GET["q"]);
$limit = strtolower($_GET["limit"]);
if (!$q) {
    return;
}
// Require the initialisation file
require_once '../../init.php';
// Required files
require_once MAX_PATH . '/lib/OA/Dal.php';
require_once MAX_PATH . '/www/admin/config.php';
// Restrict access to accounts which are allowed to link other accounts
switch (OA_Permission::getAccountType()) {
    case OA_ACCOUNT_ADMIN:
        // There are no restrictions on users that are applied to the autocomplete
        // list, as the admin account can see all accounts and therefore users in
        // its realm
        $oDbh =& OA_DB::singleton();
        $query = $oDbh->quote('%' . $q . '%');
        $doUsers = OA_Dal::factoryDO('users');
        $doUsers->whereAdd('username LIKE ' . $query . ' OR email_address LIKE ' . $query);
        $doUsers->limit($limit);
        $doUsers->find();
        while ($doUsers->fetch()) {
            echo htmlspecialchars($doUsers->user_id) . '|' . htmlspecialchars($doUsers->email_address) . '|' . htmlspecialchars($doUsers->username) . "\n";
        }
        break;
    case OA_ACCOUNT_MANAGER:
Ejemplo n.º 7
0
        case '4-1':
            OA_Permission::enforceAccount(OA_ACCOUNT_ADMIN);
            $message = 'Dynamic submenu 4-1';
            $menu = 'demo-menu-4';
            // PageHeader function needs to know the *parent* menu
            setCurrentLeftMenuSubItem('demo-menu-4-1');
            break;
        case '4-2':
            OA_Permission::enforceAccount(OA_ACCOUNT_ADMIN);
            $message = 'Dynamic submenu 4-2';
            $menu = 'demo-menu-4';
            // PageHeader function needs to know the *parent* menu
            setCurrentLeftMenuSubItem('demo-menu-4-2');
            break;
    }
    $colour = $GLOBALS['_MAX']['PREF']['demoUserInterface_demopref_' . OA_Permission::getAccountType(true)];
    //$image   = 'demoUI'.$i.'.jpg';
    $message = $message;
    addLeftMenuSubItem('demo-menu-4-1', 'demo submenu 4-1', 'plugins/demoUserInterface/demoUI-page.php?action=4-1');
    addLeftMenuSubItem('demo-menu-4-2', 'demo submenu 4-2', 'plugins/demoUserInterface/demoUI-page.php?action=4-2');
    phpAds_PageHeader($menu, '', '../../');
    $oTpl = new OA_Plugin_Template('demoUI.html', 'demoUserInterface');
    //$oTpl->assign('image',$image);
    $oTpl->assign('message', $message);
    $oTpl->assign('colour', $colour);
    $oTpl->display();
    phpAds_PageFooter();
} else {
    require_once LIB_PATH . '/Admin/Redirect.php';
    OX_Admin_Redirect::redirect('plugins/demoUserInterface/demoUI-index.php');
}
require_once MAX_PATH . '/lib/max/Plugin/Translation.php';
require_once MAX_PATH . '/www/admin/config.php';
require_once LIB_PATH . '/Plugin/ComponentGroupManager.php';
// Security check
OA_Permission::enforceAccount(OA_ACCOUNT_ADMIN, OA_ACCOUNT_MANAGER, OA_ACCOUNT_ADVERTISER, OA_ACCOUNT_TRAFFICKER);
phpAds_registerGlobal('group');
// Load the account's preferences, with additional information, into a specially named array
$GLOBALS['_MAX']['PREF_EXTRA'] = OA_Preferences::loadPreferences(true, true);
// Create a new option object for displaying the setting's page's HTML form
$oOptions = new OA_Admin_Option('preferences');
// Prepare an array for storing error messages
$aErrormessage = array();
$oComponentGroupManager = new OX_Plugin_ComponentGroupManager();
$aGroup = $oComponentGroupManager->_getComponentGroupConfiguration($group);
$enabled = $GLOBALS['_MAX']['CONF']['pluginGroupComponents'][$group];
$disabled = !$enabled && OA_Permission::getAccountType() != OA_ACCOUNT_ADMIN;
// If the settings page is a submission, deal with the form data
if (isset($_POST['submitok']) && $_POST['submitok'] == 'true') {
    // Prepare an array of the HTML elements to process, and which
    // of the preferences are checkboxes
    $aElements = array();
    foreach ($aGroup['preferences'] as $k => $v) {
        $aElements[] = $group . '_' . $v['name'];
        // Register the HTML element value
        MAX_commonRegisterGlobalsArray(array($group . '_' . $v['name']));
    }
    $aCheckboxes = array();
    // Validation
    $valid = true;
    $validationFile = MAX_PATH . $GLOBALS['_MAX']['CONF']['pluginPaths']['packages'] . $group . '/processPreferences.php';
    if (file_exists($validationFile)) {
Ejemplo n.º 9
0
 /**
  * Show page header
  *
  * @param int $ID
  * @param OA_Admin_UI_Model_PageHeaderModel $headerModel
  * @param int $imgPath deprecated
  * @param bool $showSidebar Set to false if you do not wish to show the sidebar navigation
  * @param bool $showContentFrame Set to false if you do not wish to show the content frame
  * @param bool $showMainNavigation Set to false if you do not wish to show the main navigation
  */
 function showHeader($ID = null, $oHeaderModel = null, $imgPath = "", $showSidebar = true, $showContentFrame = true, $showMainNavigation = true)
 {
     global $conf, $phpAds_CharSet, $phpAds_breadcrumbs_extra;
     $conf = $GLOBALS['_MAX']['CONF'];
     $ID = $this->getId($ID);
     $this->setCurrentId($ID);
     if (!defined('phpAds_installing')) {
         OX_Admin_UI_Hooks::beforePageHeader($ID, $this->getLinkParams(), $oHeaderModel);
     }
     $pageTitle = !empty($conf['ui']['applicationName']) ? $conf['ui']['applicationName'] : MAX_PRODUCT_NAME;
     $aMainNav = array();
     $aLeftMenuNav = array();
     $aLeftMenuSubNav = array();
     $aSectionNav = array();
     if ($ID !== phpAds_Login && $ID !== phpAds_Error && $ID !== phpAds_PasswordRecovery) {
         //get system navigation
         $oMenu = OA_Admin_Menu::singleton();
         //update page title
         $oCurrentSection = $oMenu->get($ID);
         $this->redirectSectionToCorrectUrlIfOldUrlDetected($oCurrentSection);
         if ($oCurrentSection == null) {
             phpAds_Die($GLOBALS['strErrorOccurred'], 'Menu system error: <strong>' . OA_Permission::getAccountType(true) . '::' . htmlspecialchars($ID) . '</strong> not found for the current user: you might not have sufficient permission to view this page. <br/>If the problem persists, you can also try to delete the files inside your /path/to/openx/var/cache/ directory.');
         }
         if ($oHeaderModel == null) {
             //build default model with title and name taken from nav entry
             $oHeaderModel = new OA_Admin_UI_Model_PageHeaderModel($oCurrentSection->getName());
         }
         if ($oHeaderModel->getTitle()) {
             $pageTitle .= ' - ' . $oHeaderModel->getTitle();
         } else {
             $pageTitle .= ' - ' . $oCurrentSection->getName();
         }
         // compile navigation arrays
         $this->_compileMainNavigationTabBar($oCurrentSection, $oMenu, $aMainNav);
         $this->_compileLeftMenuNavigation($oCurrentSection, $oMenu, $aLeftMenuNav);
         $this->_compileLeftSubMenuNavigation($oCurrentSection, $oMenu, $aLeftMenuSubNav);
         $this->_compileSectionTabBar($oCurrentSection, $oMenu, $aSectionNav);
     } else {
         // Build tabbed navigation bar
         if ($ID == phpAds_Login) {
             $aMainNav[] = array('title' => $GLOBALS['strAuthentification'], 'filename' => 'index.php', 'selected' => true);
         } elseif ($ID == phpAds_Error) {
             $aMainNav[] = array('title' => $GLOBALS['strErrorOccurred'], 'filename' => 'index.php', 'selected' => true);
         } elseif ($ID == phpAds_PasswordRecovery) {
             $aMainNav[] = array('title' => $GLOBALS['strPasswordRecovery'], 'filename' => 'index.php', 'selected' => true);
         }
         $showContentFrame = false;
     }
     //html header
     $this->_assignLayout($pageTitle);
     $this->_assignJavascriptandCSS();
     //layout stuff
     $this->oTpl->assign('uiPart', 'header');
     $this->oTpl->assign('showContentFrame', $showContentFrame);
     $this->oTpl->assign('showSidebar', $showSidebar);
     $this->oTpl->assign('showMainNavigation', $showMainNavigation);
     //top
     $this->_assignBranding($conf['ui']);
     $this->_assignSearch($ID);
     $this->_assignUserAccountInfo($oCurrentSection);
     $this->oTpl->assign('headerModel', $oHeaderModel);
     $this->oTpl->assign('hideNavigator', $conf['ui']['hideNavigator']);
     // Tabbed navigation bar and sidebar
     $this->oTpl->assign('aMainTabNav', $aMainNav);
     $this->oTpl->assign('aLeftMenuNav', $aLeftMenuNav);
     $this->oTpl->assign('aLeftMenuSubNav', $aLeftMenuSubNav);
     $this->oTpl->assign('aSectionNav', $aSectionNav);
     // This is used to show banner preview
     $this->oTpl->assign('breadcrumbsExtra', $phpAds_breadcrumbs_extra);
     //tools and shortcuts
     $this->oTpl->assign('aTools', $this->aTools);
     $this->oTpl->assign('aShortcuts', $this->aShortcuts);
     //additional things
     $this->_assignJavascriptDefaults();
     //JS validation messages and other defaults
     $this->_assignAlertMPE();
     //mpe xajax
     $this->_assignInstalling();
     //install indicator
     $this->_assignMessagesAndNotifications();
     //messaging system
     //html header
     $this->_assignJavascriptandCSS();
     /* DISPLAY */
     // Use gzip content compression
     if (isset($conf['ui']['gzipCompression']) && $conf['ui']['gzipCompression']) {
         //enable compression if it's not alredy handled by the zlib and ob_gzhandler is loaded
         $zlibCompression = ini_get('zlib.output_compression');
         if (!$zlibCompression && function_exists('ob_gzhandler')) {
             // enable compression only if it wasn't enabled previously (e.g by widget)
             //also, we cannot enable gzip if session was started
             $session_id = session_id();
             //check if there's any session
             if (ob_get_contents() === false && empty($session_id)) {
                 ob_start("ob_gzhandler");
             }
         }
     }
     // Send header with charset info and display
     header("Content-Type: text/html" . (isset($phpAds_CharSet) && $phpAds_CharSet != "" ? "; charset=" . $phpAds_CharSet : ""));
     $this->oTpl->display();
     if (!defined('phpAds_installing')) {
         OX_Admin_UI_Hooks::afterPageHeader($id);
     }
 }
Ejemplo n.º 10
0
 /**
  * A private method to set the required options for column-based output
  * of option items.
  *
  * @access private
  * @param array $aItem The column option to display.
  * @param array $aValue An array of the column values.
  */
 function _showStatsColumns($aItem, $aValue)
 {
     // Get all of the preference types that exist
     $aPreferenceTypes = array();
     $doPreferences = OA_Dal::factoryDO('preferences');
     $doPreferences->find();
     if ($doPreferences->getRowCount() >= 1) {
         while ($doPreferences->fetch()) {
             $aPreference = $doPreferences->toArray();
             $aPreferenceTypes[$aPreference['preference_name']] = array('preference_id' => $aPreference['preference_id'], 'account_type' => $aPreference['account_type']);
         }
     }
     // Get the type of the current accout
     $currentAccountType = OA_Permission::getAccountType();
     global $tabindex;
     $aItem['tabindex'] = $tabindex++;
     foreach ($aItem['rows'] as $key => $aRow) {
         if (isset($aValue[$aRow['name']]['base'])) {
             $aItem['rows'][$key]['value'] = $aValue[$aRow['name']]['base'];
         }
         if (isset($aValue[$aRow['name']]['label'])) {
             $aItem['rows'][$key]['label_value'] = $aValue[$aRow['name']]['label'];
         }
         if (isset($aValue[$aRow['name']]['rank'])) {
             $aItem['rows'][$key]['rank_value'] = $aValue[$aRow['name']]['rank'];
         }
         // Has the current account got access to edit this preference?
         $access = OA_Preferences::hasAccess($currentAccountType, $aPreferenceTypes[$aRow['name']]['account_type']);
         if ($access == false) {
             $aItem['rows'][$key]['disabled'] = true;
         }
     }
     $this->aOption[] = array('statscolumns.html' => $aItem);
     // Update the global tab index for the number of stats column rows added
     $rows = count($aItem['rows']);
     $tabindex += $rows * 3;
     // Not an exact increment of the tab index, but close enough!
 }
 /**
  * caches hooks for enabled plugins only
  * indexed by group name
  *
  * @return boolean
  */
 function cachePreferenceOptions()
 {
     $oComponentGroupManager = new OX_Plugin_ComponentGroupManager();
     $aComponentGroups = $GLOBALS['_MAX']['CONF']['pluginGroupComponents'] ? $GLOBALS['_MAX']['CONF']['pluginGroupComponents'] : array();
     $aOptions = array();
     foreach ($aComponentGroups as $name => $enabled) {
         if ($enabled || OA_Permission::getAccountType() == OA_ACCOUNT_ADMIN) {
             $aConfig[$name] = $oComponentGroupManager->_getComponentGroupConfiguration($name);
             if (count($aConfig[$name]['preferences'])) {
                 $aOptions[$name] = array('name' => $name, 'text' => $aConfig[$name]['option'] ? $aConfig[$name]['option'] : $name, 'value' => 'account-preferences-plugin.php?group=' . $name, 'perm' => array(OA_ACCOUNT_ADMIN, OA_ACCOUNT_MANAGER, OA_ACCOUNT_ADVERTISER, OA_ACCOUNT_TRAFFICKER));
             }
         }
     }
     $oCache = $oComponentGroupManager->_getOA_Cache('Plugins', 'PrefOptions');
     $oCache->setFileNameProtection(false);
     return $oCache->save($aOptions);
 }
Ejemplo n.º 12
0
 /**
  * A method to check if the user has specific permissions to perform
  * an action on an account
  *
  * TODOPERM - consider caching permissions in user session so they could
  *            be reused across many user requests
  *
  * @static
  * @param integer $permissionId
  * @param int $accountId
  * @return boolean
  */
 function hasPermission($permissionId, $accountId = null, $userId = null)
 {
     if (empty($userId)) {
         $userId = OA_Permission::getUserId();
     }
     if (OA_Permission::isUserLinkedToAdmin($userId)) {
         return true;
     }
     static $aCache = array();
     if (empty($accountId)) {
         $accountId = OA_Permission::getAccountId();
         $accountType = OA_Permission::getAccountType();
     } else {
         $oAccounts = OA_Dal::staticGetDO('accounts', $accountId);
         if ($oAccounts) {
             $accountType = $oAccounts->accountType;
         } else {
             // Account does not exist
             Max::raiseError('No such account ID: ' . $accountId);
             return false;
         }
     }
     if (OA_Permission::isPermissionRelatedToAccountType($accountType, $permissionId)) {
         $aCache[$userId][$accountId] = OA_Permission::getAccountUsersPermissions($userId, $accountId);
     } else {
         $aCache[$userId][$accountId][$permissionId] = true;
     }
     return isset($aCache[$userId][$accountId][$permissionId]) ? $aCache[$userId][$accountId][$permissionId] : false;
 }