function test_MAX_AclSave()
 {
     // insert a channel
     $doChannel = OA_Dal::factoryDO('channel');
     $channelId = DataGenerator::generateOne($doChannel);
     $doChannel->channelid = $channelId;
     // insert a banner
     $doBanners = OA_Dal::factoryDO('banners');
     $bannerId = DataGenerator::generateOne($doBanners);
     $doBanners->bannerid = $bannerId;
     $doBanners->acls_updated = OA::getNow();
     $doBanners->update();
     $updated1 = $doBanners->acls_updated;
     // save a banner limited by date/time
     $aAcls[1]['data'] = '0,1';
     $aAcls[1]['logical'] = 'and';
     $aAcls[1]['type'] = 'Dummy:Dummy';
     $aAcls[1]['comparison'] = '=~';
     $aAcls[1]['executionorder'] = 1;
     $sLimitation = "MAX_checkDummy_Dummy('0,1', '=~')";
     $aEntities = array('bannerid' => $bannerId);
     $this->assertTrue(MAX_AclSave(array($aAcls[1]), $aEntities, 'banner-acl.php'));
     $doBanners = OA_Dal::staticGetDO('banners', $bannerId);
     $this->assertTrue($doBanners);
     $this->assertEqual($sLimitation, $doBanners->compiledlimitation);
     $doAcls = OA_Dal::factoryDO('acls');
     $doAcls->whereAdd('bannerid = ' . $bannerId);
     $this->assertTrue($doAcls->find(true));
     $this->assertEqual($doAcls->bannerid, $bannerId);
     $this->assertEqual($doAcls->logical, $aAcls[1]['logical']);
     $this->assertEqual($doAcls->type, $aAcls[1]['type']);
     $this->assertEqual($doAcls->comparison, $aAcls[1]['comparison']);
     $this->assertEqual($doAcls->data, $aAcls[1]['data']);
     $this->assertEqual($doAcls->executionorder, $aAcls[1]['executionorder']);
     $this->assertFalse($doAcls->fetch());
 }
    $aEntities = array('agencyid' => $agencyId, 'channelid' => $channelid);
    $aOtherChannels = Admin_DA::getChannels(array('agency_id' => $agencyId, 'channel_type' => 'agency'));
}
/*-------------------------------------------------------*/
/* Process submitted form                                */
/*-------------------------------------------------------*/
if (!empty($action)) {
    if (empty($acl)) {
        $acl = array();
    }
    $acl = MAX_AclAdjust($acl, $action);
} elseif (!empty($submit)) {
    $acl = isset($acl) ? $acl : array();
    // Only save when inputs are valid
    if (OX_AclCheckInputsFields($acl, $pageName) === true) {
        if (MAX_AclSave($acl, $aEntities)) {
            // Queue confirmation message
            $doChannel = OA_Dal::factoryDO('channel');
            $doChannel->get($channelid);
            $translation = new OX_Translation();
            $translated_message = $translation->translate($GLOBALS['strChannelAclHasBeenUpdated'], array(MAX::constructURL(MAX_URL_ADMIN, "channel-edit.php?" . (!empty($affiliateid) ? "affiliateid={$affiliateid}&" : "") . "channelid={$channelid}"), htmlspecialchars($doChannel->name)));
            OA_Admin_UI::queueMessage($translated_message, 'local', 'confirm', 0);
            // Redirect
            if (!empty($affiliateid)) {
                header("Location: channel-acl.php?affiliateid={$affiliateid}&channelid={$channelid}");
            } else {
                header("Location: channel-acl.php?channelid={$channelid}");
            }
            exit;
        }
    }
/**
 * Recompiles all acls definitions for one of the type: banners or channel.
 *
 * @param string $aclsTable 'acls' or 'acls_channel'.
 * @param string $idColumn 'bannerid' or 'channelid'.
 * @param string $page 'banner-acl.php' or 'channel-acl.php'.
 * @param string $objectTable 'banners' or 'channel'
 * @return boolean True on success, PEAR::Error on failure.
 */
function OA_aclRecompileAclsForTable($aclsTable, $idColumn, $page, $objectTable, $upgrade = false)
{
    $dbh =& OA_DB::singleton();
    $prefix = $GLOBALS['_MAX']['CONF']['table']['prefix'];
    $table = $dbh->quoteIdentifier($prefix . $objectTable, true);
    $result = $dbh->exec("UPDATE {$table} SET compiledlimitation = '', acl_plugins = ''");
    if (PEAR::isError($result)) {
        return $result;
    }
    $dalAcls =& OA_Dal::factoryDAL('acls');
    $rsAcls = $dalAcls->getRsAcls($aclsTable, $idColumn);
    if (PEAR::isError($rsAcls)) {
        return $rsAcls;
    }
    $result = $rsAcls->find();
    if (PEAR::isError($result)) {
        return $result;
    }
    // Init variable to store limitation types to be upgraded
    $aUpgradeByType = array();
    // Init array to store all banner ACLs
    $aAcls = array();
    // Fetch first row
    if (!$rsAcls->fetch()) {
        // No rows, exit
        return true;
    }
    do {
        $row = $rsAcls->toArray();
        if (!isset($aUpgradeByType[$row['type']])) {
            // Plugin not loaded yet
            $oPlugin = OA_aclGetComponentFromRow($row);
            if ($oPlugin) {
                // Upgrade requested or plugin allowed
                $aUpgradeByType[$row['type']] = $upgrade || $oPlugin->isAllowed($page);
                unset($oPlugin);
            } else {
                $aUpgradeByType[$row['type']] = false;
            }
        }
        if ($aUpgradeByType[$row['type']]) {
            $aAcls[$row['executionorder']] = $row;
        }
        // Fetch next record
        $result = $rsAcls->fetch();
        // Was this the last one? Is the next record linked to another entity?
        if (!$result || $row[$idColumn] != $rsAcls->get($idColumn)) {
            // Yes, we need to save!
            $aEntities = array($idColumn => $row[$idColumn]);
            MAX_AclSave($aAcls, $aEntities, $page);
            $aAcls = array();
        }
    } while ($result);
    return true;
}
Esempio n. 4
0
/**
 * Recompiles all acls definitions for one of the type: banners or channel.
 *
 * @param string $aclsTable 'acls' or 'acls_channel'.
 * @param string $idColumn 'bannerid' or 'channelid'.
 * @param string $page 'banner-acl.php' or 'channel-acl.php'.
 * @param string $objectTable 'banners' or 'channel'
 * @return boolean True on success, PEAR::Error on failure.
 */
function OA_aclRecompileAclsForTable($aclsTable, $idColumn, $page, $objectTable, $upgrade = false)
{
    $dbh =& OA_DB::singleton();
    $prefix = $GLOBALS['_MAX']['CONF']['table']['prefix'];
    $table = $dbh->quoteIdentifier($prefix . $objectTable, true);
    $result = $dbh->exec("UPDATE {$table} SET compiledlimitation = 'true', acl_plugins = ''");
    if (PEAR::isError($result)) {
        return $result;
    }
    $dalAcls =& OA_Dal::factoryDAL('acls');
    $rsAcls = $dalAcls->getRsAcls($aclsTable);
    if (PEAR::isError($rsAcls)) {
        return $rsAcls;
    }
    $result = $rsAcls->find();
    if (PEAR::isError($result)) {
        return $result;
    }
    $aAcls = array();
    while ($rsAcls->fetch()) {
        $row = $rsAcls->toArray();
        $deliveryLimitationPlugin =& OA_aclGetComponentFromRow($row);
        if ($deliveryLimitationPlugin) {
            if ($upgrade || $deliveryLimitationPlugin->isAllowed($page)) {
                $aAcls[$row[$idColumn]][$row['executionorder']] = $row;
            }
        }
    }
    // OK so we've updated all the data values, now the hard part, we need to recompile limitations for all banners
    foreach ($aAcls as $id => $acl) {
        $aEntities = array($idColumn => $id);
        MAX_AclSave($acl, $aEntities, $page);
    }
    return true;
}