예제 #1
0
 /**
  * A static method for processing preference values from a UI form, and
  * updating the preference values in the database.
  *
  * @static
  * @param array $aElementNames An array of HTML form element names, which
  *                             are also the preference value names.
  * @param array $aCheckboxes   An array of the above HTML form element
  *                             names which are checkboxes, as these will not
  *                             be set in the form POST if unchecked, and
  *                             so need to be treated differently.
  * @return boolean True on success, false otherwise.
  */
 function processPreferencesFromForm($aElementNames, $aCheckboxes)
 {
     phpAds_registerGlobalUnslashed('token');
     if (!phpAds_SessionValidateToken($GLOBALS['token'])) {
         return false;
     }
     // Get all of the preference types that exist
     $aPreferenceTypes = array();
     $doPreferences = OA_Dal::factoryDO('preferences');
     $doPreferences->find();
     if ($doPreferences->getRowCount() < 1) {
         return false;
     }
     while ($doPreferences->fetch()) {
         $aPreference = $doPreferences->toArray();
         $aPreferenceTypes[$aPreference['preference_name']] = array('preference_id' => $aPreference['preference_id'], 'account_type' => $aPreference['account_type']);
     }
     // Are there any preference types in the system?
     if (empty($aPreferenceTypes)) {
         return false;
     }
     // Get the type of the current accout
     $currentAccountType = OA_Permission::getAccountType();
     // Get the current account's ID
     $currentAccountId = OA_Permission::getAccountId();
     // Get the parent account preferences
     $aParentPreferences = OA_Preferences::loadPreferences(false, true, true);
     // Prepare the preference values that should be saved or deleted
     $aSavePreferences = array();
     $aDeletePreferences = array();
     foreach ($aElementNames as $preferenceName) {
         // Ensure that the current account has permission to process
         // the preference type
         $access = OA_Preferences::hasAccess($currentAccountType, $aPreferenceTypes[$preferenceName]['account_type']);
         if ($access == false) {
             // Don't process this value
             continue;
         }
         // Register the HTML element value
         phpAds_registerGlobalUnslashed($preferenceName);
         // Is the HTML element value a checkbox, and unset?
         if (isset($aCheckboxes[$preferenceName]) && !isset($GLOBALS[$preferenceName])) {
             // Set the value of the element to the false string ""
             $GLOBALS[$preferenceName] = '';
         } else {
             if (isset($aCheckboxes[$preferenceName]) && $GLOBALS[$preferenceName]) {
                 // Set the value of the element to the true string "1"
                 $GLOBALS[$preferenceName] = '1';
             }
         }
         // Was the HTML element value set?
         if (isset($GLOBALS[$preferenceName])) {
             // Is the preference value different from the parent value?
             if (!isset($aParentPreferences[$preferenceName]) || $GLOBALS[$preferenceName] != $aParentPreferences[$preferenceName]) {
                 // The preference value is different from the parent, so it
                 // needs to be stored
                 $aSavePreferences[$preferenceName] = $GLOBALS[$preferenceName];
             } else {
                 if ($currentAccountType != OA_ACCOUNT_ADMIN) {
                     // The preference value is not different from the parent, so
                     // it should be deleted if not the admin account (in case it
                     // exists for the account, and so would not inherit correctly
                     // if the admin account changes preferences)
                     $aDeletePreferences[$preferenceName] = $GLOBALS[$preferenceName];
                 }
             }
         }
     }
     // Save the required preferences
     foreach ($aSavePreferences as $preferenceName => $preferenceValue) {
         $doAccount_preference_assoc = OA_Dal::factoryDO('account_preference_assoc');
         $doAccount_preference_assoc->account_id = $currentAccountId;
         $doAccount_preference_assoc->preference_id = $aPreferenceTypes[$preferenceName]['preference_id'];
         $doAccount_preference_assoc->find();
         if ($doAccount_preference_assoc->getRowCount() != 1) {
             // Insert the preference
             $doAccount_preference_assoc->value = $preferenceValue;
             $result = $doAccount_preference_assoc->insert();
             if ($result === false) {
                 return false;
             }
         } else {
             // Update the preference
             $doAccount_preference_assoc->fetch();
             $doAccount_preference_assoc->value = $preferenceValue;
             $result = $doAccount_preference_assoc->update();
             if ($result === false) {
                 return false;
             }
         }
     }
     // Delete the required preferences
     foreach ($aDeletePreferences as $preferenceName => $preferenceValue) {
         $doAccount_preference_assoc = OA_Dal::factoryDO('account_preference_assoc');
         $doAccount_preference_assoc->account_id = $currentAccountId;
         $doAccount_preference_assoc->preference_id = $aPreferenceTypes[$preferenceName]['preference_id'];
         $doAccount_preference_assoc->find();
         if ($doAccount_preference_assoc->getRowCount() == 1) {
             // Delete the preference
             $result = $doAccount_preference_assoc->delete();
             if ($result === false) {
                 return false;
             }
         }
     }
     return true;
 }
| along with this program; if not, write to the Free Software               |
| Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA |
+---------------------------------------------------------------------------+
$Id: account-preferences-campaign-email-reports.php 37157 2009-05-28 12:31:10Z andrew.hill $
*/
// Require the initialisation file
require_once '../../init.php';
// Required files
require_once MAX_PATH . '/lib/OA/Admin/Option.php';
require_once MAX_PATH . '/lib/OA/Preferences.php';
require_once MAX_PATH . '/lib/max/Plugin/Translation.php';
require_once MAX_PATH . '/www/admin/config.php';
// Security check
OA_Permission::enforceAccount(OA_ACCOUNT_ADMIN, OA_ACCOUNT_MANAGER, OA_ACCOUNT_TRAFFICKER, OA_ACCOUNT_ADVERTISER);
// 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');
$prefSection = "campaign-email-reports";
// Prepare an array for storing error messages
$aErrormessage = array();
// 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();
    $aCheckboxes = array();
    // Administrator email Warnings
    $aElements[] = 'warn_email_admin';
    $aCheckboxes['warn_email_admin'] = true;
    $aElements[] = 'warn_email_admin_impression_limit';
     $oDal = OA_Dal::factoryDAL('campaigns');
     $agencyId = OA_Permission::getAgencyId();
     $aCampaigns = $oDal->updateCampaignsPriorityByAgency($agencyId, $updateFrom, $updateTo);
     foreach ($aCampaigns as $campaignId => $aCampaign) {
         if ($aCampaign['status_changed'] && $aCampaign['status'] == OA_ENTITY_STATUS_INACTIVE) {
             // store without string indexes, to not to waste space in session
             $aInactivatedCampaignsIds[$campaignId] = array($campaignId, $aCampaign['clientid'], $aCampaign['campaignname']);
         }
     }
     $runMaintenance = true;
 }
 // We changed contract
 if ((bool) $_POST['contract_ecpm_enabled'] != (bool) $pref['contract_ecpm_enabled']) {
     // Reload the prefs we just changed into the global variable because
     // we use it when setting ecpm_enabled in the DO.
     OA_Preferences::loadPreferences();
     $oDal = OA_Dal::factoryDAL('campaigns');
     $agencyId = OA_Permission::getAgencyId();
     $aCampaigns = $oDal->updateEcpmEnabledByAgency($agencyId);
     foreach ($aCampaigns as $campaignId => $aCampaign) {
         if ($aCampaign['status_changed'] && $aCampaign['status'] == OA_ENTITY_STATUS_INACTIVE) {
             // store without string indexes, to not to waste space in session
             $aInactivatedCampaignsIds[$campaignId] = array($campaignId, $aCampaign['clientid'], $aCampaign['campaignname']);
         }
     }
     $runMaintenance = true;
 }
 // store the list of inactivated campaigns in the session
 if (!empty($aInactivatedCampaignsIds)) {
     $session['aInactivatedCampaignsIds'] = $aInactivatedCampaignsIds;
     phpAds_SessionDataStore();
 /**
  * A method to test the OA_Preferences::loadPreferences() method
  * when the preferences should be loaded in a two-dimensional
  * array.
  */
 function testLoadPreferencesTwoDimensional()
 {
     // Test 1: Test with no user logged in, and ensure that no
     //         preferences are loaded.
     unset($GLOBALS['_MAX']['PREF']);
     unset($GLOBALS['_MAX']['CONF']['max']['language']);
     OA_Preferences::loadPreferences(true);
     $this->assertNull($GLOBALS['_MAX']['PREF']);
     // Test 2: Test with no user logged in, and ensure that no
     //         preferences are loaded, and that esisting preferences
     //         that may exist are removed.
     $GLOBALS['_MAX']['PREF'] = array('foo' => 'bar');
     $this->assertNotNull($GLOBALS['_MAX']['PREF']);
     OA_Preferences::loadPreferences(true);
     $this->assertNull($GLOBALS['_MAX']['PREF']);
     // Create the admin account
     $doAccounts = OA_Dal::factoryDO('accounts');
     $doAccounts->account_name = 'System Administrator';
     $doAccounts->account_type = OA_ACCOUNT_ADMIN;
     $adminAccountId = DataGenerator::generateOne($doAccounts);
     // Create a user
     $doUsers = OA_Dal::factoryDO('users');
     $doUsers->contact_name = 'Andrew Hill';
     $doUsers->email_address = '*****@*****.**';
     $doUsers->username = '******';
     $doUsers->password = md5('password');
     $doUsers->default_account_id = $adminAccountId;
     $userId = DataGenerator::generateOne($doUsers);
     // Create admin association
     $doAUA = OA_Dal::factoryDO('account_user_assoc');
     $doAUA->account_id = $adminAccountId;
     $doAUA->user_id = $userId;
     $doAUA->insert();
     // Ensure this user is "logged in"
     $doUsers = OA_Dal::factoryDO('users');
     $doUsers->username = '******';
     $doUsers->find();
     $doUsers->fetch();
     $oUser = new OA_Permission_User($doUsers);
     global $session;
     $session['user'] = $oUser;
     // Test 3: Test with the admin account logged in, but no preferences in
     //         the system, and ensure that no preferences are loaded, and
     //         that esisting preferences that may exist are removed.
     $GLOBALS['_MAX']['PREF'] = array('foo' => 'bar');
     $this->assertNotNull($GLOBALS['_MAX']['PREF']);
     OA_Preferences::loadPreferences(true);
     $this->assertNull($GLOBALS['_MAX']['PREF']);
     // Prepare a fake preference
     $doPreferences = OA_Dal::factoryDO('preferences');
     $doPreferences->preference_name = 'preference_1';
     $doPreferences->account_type = OA_ACCOUNT_ADMIN;
     $preferenceId = DataGenerator::generateOne($doPreferences);
     // Test 4: Test with the admin user logged in, and a preference in
     //         the system, but no preference values set for the admin account.
     $GLOBALS['_MAX']['PREF'] = array('foo' => 'bar');
     $this->assertNotNull($GLOBALS['_MAX']['PREF']);
     OA_Preferences::loadPreferences(true);
     $this->assertNull($GLOBALS['_MAX']['PREF']);
     // Insert a fake preference value
     $doAccount_Preference_Assoc = OA_Dal::factoryDO('account_preference_assoc');
     $doAccount_Preference_Assoc->account_id = $adminAccountId;
     $doAccount_Preference_Assoc->preference_id = $preferenceId;
     $doAccount_Preference_Assoc->value = 'foo!';
     DataGenerator::generateOne($doAccount_Preference_Assoc);
     // Test 5: Test with the admin account logged in, a preference in the
     //         system, and a preference value set for the admin account.
     $GLOBALS['_MAX']['PREF'] = array('foo' => 'bar');
     $this->assertNotNull($GLOBALS['_MAX']['PREF']);
     OA_Preferences::loadPreferences(true);
     $this->assertNotNull($GLOBALS['_MAX']['PREF']);
     $this->assertTrue(is_array($GLOBALS['_MAX']['PREF']));
     $this->assertEqual(count($GLOBALS['_MAX']['PREF']), 2);
     $this->assertNotNull($GLOBALS['_MAX']['PREF']['preference_1']);
     $this->assertTrue(is_array($GLOBALS['_MAX']['PREF']['preference_1']));
     $this->assertEqual(count($GLOBALS['_MAX']['PREF']['preference_1']), 2);
     $this->assertNotNull($GLOBALS['_MAX']['PREF']['preference_1']['account_type']);
     $this->assertEqual($GLOBALS['_MAX']['PREF']['preference_1']['account_type'], OA_ACCOUNT_ADMIN);
     $this->assertNotNull($GLOBALS['_MAX']['PREF']['preference_1']['value']);
     $this->assertEqual($GLOBALS['_MAX']['PREF']['preference_1']['value'], 'foo!');
     // Prepare a second fake preference
     $doPreferences = OA_Dal::factoryDO('preferences');
     $doPreferences->preference_name = 'preference_2';
     $doPreferences->account_type = OA_ACCOUNT_MANAGER;
     $preferenceId = DataGenerator::generateOne($doPreferences);
     // Test 6: Test with the admin account logged in, two preferences in the
     //         system, and one preference value set for the admin account.
     $GLOBALS['_MAX']['PREF'] = array('foo' => 'bar');
     $this->assertNotNull($GLOBALS['_MAX']['PREF']);
     OA_Preferences::loadPreferences(true);
     $this->assertNotNull($GLOBALS['_MAX']['PREF']);
     $this->assertTrue(is_array($GLOBALS['_MAX']['PREF']));
     $this->assertEqual(count($GLOBALS['_MAX']['PREF']), 3);
     $this->assertNotNull($GLOBALS['_MAX']['PREF']['preference_1']);
     $this->assertTrue(is_array($GLOBALS['_MAX']['PREF']['preference_1']));
     $this->assertEqual(count($GLOBALS['_MAX']['PREF']['preference_1']), 2);
     $this->assertNotNull($GLOBALS['_MAX']['PREF']['preference_1']['account_type']);
     $this->assertEqual($GLOBALS['_MAX']['PREF']['preference_1']['account_type'], OA_ACCOUNT_ADMIN);
     $this->assertNotNull($GLOBALS['_MAX']['PREF']['preference_1']['value']);
     $this->assertEqual($GLOBALS['_MAX']['PREF']['preference_1']['value'], 'foo!');
     $this->assertNotNull($GLOBALS['_MAX']['PREF']['preference_2']);
     $this->assertTrue(is_array($GLOBALS['_MAX']['PREF']['preference_2']));
     $this->assertEqual(count($GLOBALS['_MAX']['PREF']['preference_2']), 1);
     $this->assertNotNull($GLOBALS['_MAX']['PREF']['preference_2']['account_type']);
     $this->assertEqual($GLOBALS['_MAX']['PREF']['preference_2']['account_type'], OA_ACCOUNT_MANAGER);
     // Insert a second fake preference value
     $doAccount_Preference_Assoc = OA_Dal::factoryDO('account_preference_assoc');
     $doAccount_Preference_Assoc->account_id = $adminAccountId;
     $doAccount_Preference_Assoc->preference_id = $preferenceId;
     $doAccount_Preference_Assoc->value = 'bar!';
     DataGenerator::generateOne($doAccount_Preference_Assoc);
     // Test 7: Test with the admin account logged in, two preferences in the
     //         system, and two preference value set for the admin account.
     $GLOBALS['_MAX']['PREF'] = array('foo' => 'bar');
     $this->assertNotNull($GLOBALS['_MAX']['PREF']);
     OA_Preferences::loadPreferences(true);
     $this->assertNotNull($GLOBALS['_MAX']['PREF']);
     $this->assertTrue(is_array($GLOBALS['_MAX']['PREF']));
     $this->assertEqual(count($GLOBALS['_MAX']['PREF']), 3);
     $this->assertNotNull($GLOBALS['_MAX']['PREF']['preference_1']);
     $this->assertTrue(is_array($GLOBALS['_MAX']['PREF']['preference_1']));
     $this->assertEqual(count($GLOBALS['_MAX']['PREF']['preference_1']), 2);
     $this->assertNotNull($GLOBALS['_MAX']['PREF']['preference_1']['account_type']);
     $this->assertEqual($GLOBALS['_MAX']['PREF']['preference_1']['account_type'], OA_ACCOUNT_ADMIN);
     $this->assertNotNull($GLOBALS['_MAX']['PREF']['preference_1']['value']);
     $this->assertEqual($GLOBALS['_MAX']['PREF']['preference_1']['value'], 'foo!');
     $this->assertNotNull($GLOBALS['_MAX']['PREF']['preference_2']);
     $this->assertTrue(is_array($GLOBALS['_MAX']['PREF']['preference_2']));
     $this->assertEqual(count($GLOBALS['_MAX']['PREF']['preference_2']), 2);
     $this->assertNotNull($GLOBALS['_MAX']['PREF']['preference_2']['account_type']);
     $this->assertEqual($GLOBALS['_MAX']['PREF']['preference_2']['account_type'], OA_ACCOUNT_MANAGER);
     $this->assertNotNull($GLOBALS['_MAX']['PREF']['preference_2']['value']);
     $this->assertEqual($GLOBALS['_MAX']['PREF']['preference_2']['value'], 'bar!');
     // Create a manager "agency" and account
     $doAgency = OA_Dal::factoryDO('agency');
     $doAgency->name = 'Manager Account';
     $doAgency->contact = 'Andrew Hill';
     $doAgency->email = '*****@*****.**';
     $managerAgencyId = DataGenerator::generateOne($doAgency);
     // Get the account ID for the manager "agency"
     $doAgency = OA_Dal::factoryDO('agency');
     $doAgency->agency_id = $managerAgencyId;
     $doAgency->find();
     $doAgency->fetch();
     $aAgency = $doAgency->toArray();
     $managerAccountId = $aAgency['account_id'];
     // Update the existing user to log into the manager account by default
     $doUsers = OA_Dal::factoryDO('users');
     $doUsers->username = '******';
     $doUsers->find();
     $doUsers->fetch();
     $doUsers->default_account_id = $managerAccountId;
     $doUsers->update();
     // Ensure this user is "logged in"
     $doUsers = OA_Dal::factoryDO('users');
     $doUsers->username = '******';
     $doUsers->find();
     $doUsers->fetch();
     $oUser = new OA_Permission_User($doUsers);
     global $session;
     $session['user'] = $oUser;
     // Test 8: Test with the manager account logged in, two preferences in the
     //         system, and two preference value set for the admin account.
     $GLOBALS['_MAX']['PREF'] = array('foo' => 'bar');
     $this->assertNotNull($GLOBALS['_MAX']['PREF']);
     OA_Preferences::loadPreferences(true);
     $this->assertNotNull($GLOBALS['_MAX']['PREF']);
     $this->assertTrue(is_array($GLOBALS['_MAX']['PREF']));
     $this->assertEqual(count($GLOBALS['_MAX']['PREF']), 3);
     $this->assertNotNull($GLOBALS['_MAX']['PREF']['preference_1']);
     $this->assertTrue(is_array($GLOBALS['_MAX']['PREF']['preference_1']));
     $this->assertEqual(count($GLOBALS['_MAX']['PREF']['preference_1']), 2);
     $this->assertNotNull($GLOBALS['_MAX']['PREF']['preference_1']['account_type']);
     $this->assertEqual($GLOBALS['_MAX']['PREF']['preference_1']['account_type'], OA_ACCOUNT_ADMIN);
     $this->assertNotNull($GLOBALS['_MAX']['PREF']['preference_1']['value']);
     $this->assertEqual($GLOBALS['_MAX']['PREF']['preference_1']['value'], 'foo!');
     $this->assertNotNull($GLOBALS['_MAX']['PREF']['preference_2']);
     $this->assertTrue(is_array($GLOBALS['_MAX']['PREF']['preference_2']));
     $this->assertEqual(count($GLOBALS['_MAX']['PREF']['preference_2']), 2);
     $this->assertNotNull($GLOBALS['_MAX']['PREF']['preference_2']['account_type']);
     $this->assertEqual($GLOBALS['_MAX']['PREF']['preference_2']['account_type'], OA_ACCOUNT_MANAGER);
     $this->assertNotNull($GLOBALS['_MAX']['PREF']['preference_2']['value']);
     $this->assertEqual($GLOBALS['_MAX']['PREF']['preference_2']['value'], 'bar!');
     // Overwrite preference_2 at the manager account level
     $doAccount_Preference_Assoc = OA_Dal::factoryDO('account_preference_assoc');
     $doAccount_Preference_Assoc->account_id = $managerAccountId;
     $doAccount_Preference_Assoc->preference_id = $preferenceId;
     $doAccount_Preference_Assoc->value = 'baz!';
     DataGenerator::generateOne($doAccount_Preference_Assoc);
     // Test 9: Test with the manager account logged in, two preferences in the
     //         system, two preference value set for the admin account, with
     //         one of them overwritten by the manager account.
     $GLOBALS['_MAX']['PREF'] = array('foo' => 'bar');
     $this->assertNotNull($GLOBALS['_MAX']['PREF']);
     OA_Preferences::loadPreferences(true);
     $this->assertNotNull($GLOBALS['_MAX']['PREF']);
     $this->assertTrue(is_array($GLOBALS['_MAX']['PREF']));
     $this->assertEqual(count($GLOBALS['_MAX']['PREF']), 3);
     $this->assertNotNull($GLOBALS['_MAX']['PREF']['preference_1']);
     $this->assertTrue(is_array($GLOBALS['_MAX']['PREF']['preference_1']));
     $this->assertEqual(count($GLOBALS['_MAX']['PREF']['preference_1']), 2);
     $this->assertNotNull($GLOBALS['_MAX']['PREF']['preference_1']['account_type']);
     $this->assertEqual($GLOBALS['_MAX']['PREF']['preference_1']['account_type'], OA_ACCOUNT_ADMIN);
     $this->assertNotNull($GLOBALS['_MAX']['PREF']['preference_1']['value']);
     $this->assertEqual($GLOBALS['_MAX']['PREF']['preference_1']['value'], 'foo!');
     $this->assertNotNull($GLOBALS['_MAX']['PREF']['preference_2']);
     $this->assertTrue(is_array($GLOBALS['_MAX']['PREF']['preference_2']));
     $this->assertEqual(count($GLOBALS['_MAX']['PREF']['preference_2']), 2);
     $this->assertNotNull($GLOBALS['_MAX']['PREF']['preference_2']['account_type']);
     $this->assertEqual($GLOBALS['_MAX']['PREF']['preference_2']['account_type'], OA_ACCOUNT_MANAGER);
     $this->assertNotNull($GLOBALS['_MAX']['PREF']['preference_2']['value']);
     $this->assertEqual($GLOBALS['_MAX']['PREF']['preference_2']['value'], 'baz!');
     // Update the existing user to log into the admin account by default
     $doUsers = OA_Dal::factoryDO('users');
     $doUsers->username = '******';
     $doUsers->find();
     $doUsers->fetch();
     $doUsers->default_account_id = $adminAccountId;
     $doUsers->update();
     // Ensure this user is "logged in"
     $doUsers = OA_Dal::factoryDO('users');
     $doUsers->username = '******';
     $doUsers->find();
     $doUsers->fetch();
     $oUser = new OA_Permission_User($doUsers);
     global $session;
     $session['user'] = $oUser;
     // Test 10: Test with the admin account logged in, two preferences in the
     //          system, two preference value set for the admin account, with
     //          one of them overwritten by the manager account.
     $GLOBALS['_MAX']['PREF'] = array('foo' => 'bar');
     $this->assertNotNull($GLOBALS['_MAX']['PREF']);
     OA_Preferences::loadPreferences(true);
     $this->assertNotNull($GLOBALS['_MAX']['PREF']);
     $this->assertTrue(is_array($GLOBALS['_MAX']['PREF']));
     $this->assertEqual(count($GLOBALS['_MAX']['PREF']), 3);
     $this->assertNotNull($GLOBALS['_MAX']['PREF']['preference_1']);
     $this->assertTrue(is_array($GLOBALS['_MAX']['PREF']['preference_1']));
     $this->assertEqual(count($GLOBALS['_MAX']['PREF']['preference_1']), 2);
     $this->assertNotNull($GLOBALS['_MAX']['PREF']['preference_1']['account_type']);
     $this->assertEqual($GLOBALS['_MAX']['PREF']['preference_1']['account_type'], OA_ACCOUNT_ADMIN);
     $this->assertNotNull($GLOBALS['_MAX']['PREF']['preference_1']['value']);
     $this->assertEqual($GLOBALS['_MAX']['PREF']['preference_1']['value'], 'foo!');
     $this->assertNotNull($GLOBALS['_MAX']['PREF']['preference_2']);
     $this->assertTrue(is_array($GLOBALS['_MAX']['PREF']['preference_2']));
     $this->assertEqual(count($GLOBALS['_MAX']['PREF']['preference_2']), 2);
     $this->assertNotNull($GLOBALS['_MAX']['PREF']['preference_2']['account_type']);
     $this->assertEqual($GLOBALS['_MAX']['PREF']['preference_2']['account_type'], OA_ACCOUNT_MANAGER);
     $this->assertNotNull($GLOBALS['_MAX']['PREF']['preference_2']['value']);
     $this->assertEqual($GLOBALS['_MAX']['PREF']['preference_2']['value'], 'bar!');
     // Create an advertiser "client" and account, owned by the manager
     $doClients = OA_Dal::factoryDO('clients');
     $doClients->name = 'Advertiser Account';
     $doClients->contact = 'Andrew Hill';
     $doClients->email = '*****@*****.**';
     $doClients->agencyid = $managerAgencyId;
     $advertiserClientId = DataGenerator::generateOne($doClients);
     // Get the account ID for the advertiser "client"
     $doClients = OA_Dal::factoryDO('clients');
     $doClients->clientid = $advertiserClientId;
     $doClients->find();
     $doClients->fetch();
     $aAdvertiser = $doClients->toArray();
     $advertiserAccountId = $aAdvertiser['account_id'];
     // Update the existing user to log into the advertiser account by default
     $doUsers = OA_Dal::factoryDO('users');
     $doUsers->username = '******';
     $doUsers->find();
     $doUsers->fetch();
     $doUsers->default_account_id = $advertiserAccountId;
     $doUsers->update();
     // Ensure this user is "logged in"
     $doUsers = OA_Dal::factoryDO('users');
     $doUsers->username = '******';
     $doUsers->find();
     $doUsers->fetch();
     $oUser = new OA_Permission_User($doUsers);
     global $session;
     $session['user'] = $oUser;
     // Test 11: Test with the advertiser account logged in, two preferences in the
     //          system, two preference value set for the admin account, with
     //          one of them overwritten by the manager account.
     $GLOBALS['_MAX']['PREF'] = array('foo' => 'bar');
     $this->assertNotNull($GLOBALS['_MAX']['PREF']);
     OA_Preferences::loadPreferences(true);
     $this->assertNotNull($GLOBALS['_MAX']['PREF']);
     $this->assertTrue(is_array($GLOBALS['_MAX']['PREF']));
     $this->assertEqual(count($GLOBALS['_MAX']['PREF']), 3);
     $this->assertNotNull($GLOBALS['_MAX']['PREF']['preference_1']);
     $this->assertTrue(is_array($GLOBALS['_MAX']['PREF']['preference_1']));
     $this->assertEqual(count($GLOBALS['_MAX']['PREF']['preference_1']), 2);
     $this->assertNotNull($GLOBALS['_MAX']['PREF']['preference_1']['account_type']);
     $this->assertEqual($GLOBALS['_MAX']['PREF']['preference_1']['account_type'], OA_ACCOUNT_ADMIN);
     $this->assertNotNull($GLOBALS['_MAX']['PREF']['preference_1']['value']);
     $this->assertEqual($GLOBALS['_MAX']['PREF']['preference_1']['value'], 'foo!');
     $this->assertNotNull($GLOBALS['_MAX']['PREF']['preference_2']);
     $this->assertTrue(is_array($GLOBALS['_MAX']['PREF']['preference_2']));
     $this->assertEqual(count($GLOBALS['_MAX']['PREF']['preference_2']), 2);
     $this->assertNotNull($GLOBALS['_MAX']['PREF']['preference_2']['account_type']);
     $this->assertEqual($GLOBALS['_MAX']['PREF']['preference_2']['account_type'], OA_ACCOUNT_MANAGER);
     $this->assertNotNull($GLOBALS['_MAX']['PREF']['preference_2']['value']);
     $this->assertEqual($GLOBALS['_MAX']['PREF']['preference_2']['value'], 'baz!');
     // Prepare a third fake preference
     $doPreferences = OA_Dal::factoryDO('preferences');
     $doPreferences->preference_name = 'preference_3';
     $doPreferences->account_type = OA_ACCOUNT_ADVERTISER;
     $preferenceId = DataGenerator::generateOne($doPreferences);
     // Insert a third fake preference value
     $doAccount_Preference_Assoc = OA_Dal::factoryDO('account_preference_assoc');
     $doAccount_Preference_Assoc->account_id = $adminAccountId;
     $doAccount_Preference_Assoc->preference_id = $preferenceId;
     $doAccount_Preference_Assoc->value = 'Admin Preference for Preference 3';
     DataGenerator::generateOne($doAccount_Preference_Assoc);
     // Test 12: Test with the advertiser account logged in, three preferences in the
     //          system, three preference value set for the admin account, with
     //          one of them overwritten by the manager account.
     $GLOBALS['_MAX']['PREF'] = array('foo' => 'bar');
     $this->assertNotNull($GLOBALS['_MAX']['PREF']);
     OA_Preferences::loadPreferences(true);
     $this->assertNotNull($GLOBALS['_MAX']['PREF']);
     $this->assertTrue(is_array($GLOBALS['_MAX']['PREF']));
     $this->assertEqual(count($GLOBALS['_MAX']['PREF']), 4);
     $this->assertNotNull($GLOBALS['_MAX']['PREF']['preference_1']);
     $this->assertTrue(is_array($GLOBALS['_MAX']['PREF']['preference_1']));
     $this->assertEqual(count($GLOBALS['_MAX']['PREF']['preference_1']), 2);
     $this->assertNotNull($GLOBALS['_MAX']['PREF']['preference_1']['account_type']);
     $this->assertEqual($GLOBALS['_MAX']['PREF']['preference_1']['account_type'], OA_ACCOUNT_ADMIN);
     $this->assertNotNull($GLOBALS['_MAX']['PREF']['preference_1']['value']);
     $this->assertEqual($GLOBALS['_MAX']['PREF']['preference_1']['value'], 'foo!');
     $this->assertNotNull($GLOBALS['_MAX']['PREF']['preference_2']);
     $this->assertTrue(is_array($GLOBALS['_MAX']['PREF']['preference_2']));
     $this->assertEqual(count($GLOBALS['_MAX']['PREF']['preference_2']), 2);
     $this->assertNotNull($GLOBALS['_MAX']['PREF']['preference_2']['account_type']);
     $this->assertEqual($GLOBALS['_MAX']['PREF']['preference_2']['account_type'], OA_ACCOUNT_MANAGER);
     $this->assertNotNull($GLOBALS['_MAX']['PREF']['preference_2']['value']);
     $this->assertEqual($GLOBALS['_MAX']['PREF']['preference_2']['value'], 'baz!');
     $this->assertNotNull($GLOBALS['_MAX']['PREF']['preference_3']);
     $this->assertTrue(is_array($GLOBALS['_MAX']['PREF']['preference_3']));
     $this->assertEqual(count($GLOBALS['_MAX']['PREF']['preference_3']), 2);
     $this->assertNotNull($GLOBALS['_MAX']['PREF']['preference_3']['account_type']);
     $this->assertEqual($GLOBALS['_MAX']['PREF']['preference_3']['account_type'], OA_ACCOUNT_ADVERTISER);
     $this->assertNotNull($GLOBALS['_MAX']['PREF']['preference_3']['value']);
     $this->assertEqual($GLOBALS['_MAX']['PREF']['preference_3']['value'], 'Admin Preference for Preference 3');
     // Overwrite preference_3 at the advertiser account level
     $doAccount_Preference_Assoc = OA_Dal::factoryDO('account_preference_assoc');
     $doAccount_Preference_Assoc->account_id = $advertiserAccountId;
     $doAccount_Preference_Assoc->preference_id = $preferenceId;
     $doAccount_Preference_Assoc->value = 'Advertiser Preference for Preference 3';
     DataGenerator::generateOne($doAccount_Preference_Assoc);
     // Test 13: Test with the advertiser account logged in, three preferences in the
     //          system, three preference value set for the admin account, with
     //          one of them overwritten by the manager account, and another
     //          overwritten by the advertiser account.
     $GLOBALS['_MAX']['PREF'] = array('foo' => 'bar');
     $this->assertNotNull($GLOBALS['_MAX']['PREF']);
     OA_Preferences::loadPreferences(true);
     $this->assertNotNull($GLOBALS['_MAX']['PREF']);
     $this->assertTrue(is_array($GLOBALS['_MAX']['PREF']));
     $this->assertEqual(count($GLOBALS['_MAX']['PREF']), 4);
     $this->assertNotNull($GLOBALS['_MAX']['PREF']['preference_1']);
     $this->assertTrue(is_array($GLOBALS['_MAX']['PREF']['preference_1']));
     $this->assertEqual(count($GLOBALS['_MAX']['PREF']['preference_1']), 2);
     $this->assertNotNull($GLOBALS['_MAX']['PREF']['preference_1']['account_type']);
     $this->assertEqual($GLOBALS['_MAX']['PREF']['preference_1']['account_type'], OA_ACCOUNT_ADMIN);
     $this->assertNotNull($GLOBALS['_MAX']['PREF']['preference_1']['value']);
     $this->assertEqual($GLOBALS['_MAX']['PREF']['preference_1']['value'], 'foo!');
     $this->assertNotNull($GLOBALS['_MAX']['PREF']['preference_2']);
     $this->assertTrue(is_array($GLOBALS['_MAX']['PREF']['preference_2']));
     $this->assertEqual(count($GLOBALS['_MAX']['PREF']['preference_2']), 2);
     $this->assertNotNull($GLOBALS['_MAX']['PREF']['preference_2']['account_type']);
     $this->assertEqual($GLOBALS['_MAX']['PREF']['preference_2']['account_type'], OA_ACCOUNT_MANAGER);
     $this->assertNotNull($GLOBALS['_MAX']['PREF']['preference_2']['value']);
     $this->assertEqual($GLOBALS['_MAX']['PREF']['preference_2']['value'], 'baz!');
     $this->assertNotNull($GLOBALS['_MAX']['PREF']['preference_3']);
     $this->assertTrue(is_array($GLOBALS['_MAX']['PREF']['preference_3']));
     $this->assertEqual(count($GLOBALS['_MAX']['PREF']['preference_3']), 2);
     $this->assertNotNull($GLOBALS['_MAX']['PREF']['preference_3']['account_type']);
     $this->assertEqual($GLOBALS['_MAX']['PREF']['preference_3']['account_type'], OA_ACCOUNT_ADVERTISER);
     $this->assertNotNull($GLOBALS['_MAX']['PREF']['preference_3']['value']);
     $this->assertEqual($GLOBALS['_MAX']['PREF']['preference_3']['value'], 'Advertiser Preference for Preference 3');
     // Update the existing user to log into the manager account by default
     $doUsers = OA_Dal::factoryDO('users');
     $doUsers->username = '******';
     $doUsers->find();
     $doUsers->fetch();
     $doUsers->default_account_id = $managerAccountId;
     $doUsers->update();
     // Ensure this user is "logged in"
     $doUsers = OA_Dal::factoryDO('users');
     $doUsers->username = '******';
     $doUsers->find();
     $doUsers->fetch();
     $oUser = new OA_Permission_User($doUsers);
     global $session;
     $session['user'] = $oUser;
     // Test 14: Test with the manager account logged in, three preferences in the
     //          system, three preference value set for the admin account, with
     //          one of them overwritten by the manager account, and another
     //          overwritten by the advertiser account.
     $GLOBALS['_MAX']['PREF'] = array('foo' => 'bar');
     $this->assertNotNull($GLOBALS['_MAX']['PREF']);
     OA_Preferences::loadPreferences(true);
     $this->assertNotNull($GLOBALS['_MAX']['PREF']);
     $this->assertTrue(is_array($GLOBALS['_MAX']['PREF']));
     $this->assertEqual(count($GLOBALS['_MAX']['PREF']), 4);
     $this->assertNotNull($GLOBALS['_MAX']['PREF']['preference_1']);
     $this->assertTrue(is_array($GLOBALS['_MAX']['PREF']['preference_1']));
     $this->assertEqual(count($GLOBALS['_MAX']['PREF']['preference_1']), 2);
     $this->assertNotNull($GLOBALS['_MAX']['PREF']['preference_1']['account_type']);
     $this->assertEqual($GLOBALS['_MAX']['PREF']['preference_1']['account_type'], OA_ACCOUNT_ADMIN);
     $this->assertNotNull($GLOBALS['_MAX']['PREF']['preference_1']['value']);
     $this->assertEqual($GLOBALS['_MAX']['PREF']['preference_1']['value'], 'foo!');
     $this->assertNotNull($GLOBALS['_MAX']['PREF']['preference_2']);
     $this->assertTrue(is_array($GLOBALS['_MAX']['PREF']['preference_2']));
     $this->assertEqual(count($GLOBALS['_MAX']['PREF']['preference_2']), 2);
     $this->assertNotNull($GLOBALS['_MAX']['PREF']['preference_2']['account_type']);
     $this->assertEqual($GLOBALS['_MAX']['PREF']['preference_2']['account_type'], OA_ACCOUNT_MANAGER);
     $this->assertNotNull($GLOBALS['_MAX']['PREF']['preference_2']['value']);
     $this->assertEqual($GLOBALS['_MAX']['PREF']['preference_2']['value'], 'baz!');
     $this->assertNotNull($GLOBALS['_MAX']['PREF']['preference_3']);
     $this->assertTrue(is_array($GLOBALS['_MAX']['PREF']['preference_3']));
     $this->assertEqual(count($GLOBALS['_MAX']['PREF']['preference_3']), 2);
     $this->assertNotNull($GLOBALS['_MAX']['PREF']['preference_3']['account_type']);
     $this->assertEqual($GLOBALS['_MAX']['PREF']['preference_3']['account_type'], OA_ACCOUNT_ADVERTISER);
     $this->assertNotNull($GLOBALS['_MAX']['PREF']['preference_3']['value']);
     $this->assertEqual($GLOBALS['_MAX']['PREF']['preference_3']['value'], 'Admin Preference for Preference 3');
     // Update the existing user to log into the admin account by default
     $doUsers = OA_Dal::factoryDO('users');
     $doUsers->username = '******';
     $doUsers->find();
     $doUsers->fetch();
     $doUsers->default_account_id = $adminAccountId;
     $doUsers->update();
     // Ensure this user is "logged in"
     $doUsers = OA_Dal::factoryDO('users');
     $doUsers->username = '******';
     $doUsers->find();
     $doUsers->fetch();
     $oUser = new OA_Permission_User($doUsers);
     global $session;
     $session['user'] = $oUser;
     // Test 14: Test with the admin account logged in, three preferences in the
     //          system, three preference value set for the admin account, with
     //          one of them overwritten by the manager account, and another
     //          overwritten by the advertiser account.
     $GLOBALS['_MAX']['PREF'] = array('foo' => 'bar');
     $this->assertNotNull($GLOBALS['_MAX']['PREF']);
     OA_Preferences::loadPreferences(true);
     $this->assertNotNull($GLOBALS['_MAX']['PREF']);
     $this->assertTrue(is_array($GLOBALS['_MAX']['PREF']));
     $this->assertEqual(count($GLOBALS['_MAX']['PREF']), 4);
     $this->assertNotNull($GLOBALS['_MAX']['PREF']['preference_1']);
     $this->assertTrue(is_array($GLOBALS['_MAX']['PREF']['preference_1']));
     $this->assertEqual(count($GLOBALS['_MAX']['PREF']['preference_1']), 2);
     $this->assertNotNull($GLOBALS['_MAX']['PREF']['preference_1']['account_type']);
     $this->assertEqual($GLOBALS['_MAX']['PREF']['preference_1']['account_type'], OA_ACCOUNT_ADMIN);
     $this->assertNotNull($GLOBALS['_MAX']['PREF']['preference_1']['value']);
     $this->assertEqual($GLOBALS['_MAX']['PREF']['preference_1']['value'], 'foo!');
     $this->assertNotNull($GLOBALS['_MAX']['PREF']['preference_2']);
     $this->assertTrue(is_array($GLOBALS['_MAX']['PREF']['preference_2']));
     $this->assertEqual(count($GLOBALS['_MAX']['PREF']['preference_2']), 2);
     $this->assertNotNull($GLOBALS['_MAX']['PREF']['preference_2']['account_type']);
     $this->assertEqual($GLOBALS['_MAX']['PREF']['preference_2']['account_type'], OA_ACCOUNT_MANAGER);
     $this->assertNotNull($GLOBALS['_MAX']['PREF']['preference_2']['value']);
     $this->assertEqual($GLOBALS['_MAX']['PREF']['preference_2']['value'], 'bar!');
     $this->assertNotNull($GLOBALS['_MAX']['PREF']['preference_3']);
     $this->assertTrue(is_array($GLOBALS['_MAX']['PREF']['preference_3']));
     $this->assertEqual(count($GLOBALS['_MAX']['PREF']['preference_3']), 2);
     $this->assertNotNull($GLOBALS['_MAX']['PREF']['preference_3']['account_type']);
     $this->assertEqual($GLOBALS['_MAX']['PREF']['preference_3']['account_type'], OA_ACCOUNT_ADVERTISER);
     $this->assertNotNull($GLOBALS['_MAX']['PREF']['preference_3']['value']);
     $this->assertEqual($GLOBALS['_MAX']['PREF']['preference_3']['value'], 'Admin Preference for Preference 3');
 }
예제 #5
0
 /**
  * Post init session
  *
  */
 function postInitSession()
 {
     global $session, $pref;
     global $affiliateid, $agencyid, $bannerid, $campaignid, $channelid;
     global $clientid, $day, $trackerid, $userlogid, $zoneid;
     // Overwrite certain preset preferences
     if (!empty($session['language']) && $session['language'] != $GLOBALS['pref']['language']) {
         $GLOBALS['_MAX']['CONF']['max']['language'] = $session['language'];
     }
     // Load the user preferences from the database
     OA_Preferences::loadPreferences();
     // Load the required language files
     Language_Loader::load('default');
     // Register variables
     phpAds_registerGlobalUnslashed('affiliateid', 'agencyid', 'bannerid', 'campaignid', 'channelid', 'clientid', 'day', 'trackerid', 'userlogid', 'zoneid');
     if (!isset($affiliateid)) {
         $affiliateid = '';
     }
     if (!isset($agencyid)) {
         $agencyid = OA_Permission::getAgencyId();
     }
     if (!isset($bannerid)) {
         $bannerid = '';
     }
     if (!isset($campaignid)) {
         $campaignid = '';
     }
     if (!isset($channelid)) {
         $channelid = '';
     }
     if (!isset($clientid)) {
         $clientid = '';
     }
     if (!isset($day)) {
         $day = '';
     }
     if (!isset($trackerid)) {
         $trackerid = '';
     }
     if (!isset($userlogid)) {
         $userlogid = '';
     }
     if (!isset($zoneid)) {
         $zoneid = '';
     }
 }