Exemplo n.º 1
0
    /**
     * Initialise the IWmyrole module creating module vars
     * @author Albert Pérez Monfort (aperezm@xtec.cat)
     * @author Josep Ferràndiz Farré (jferran6@xtec.cat)
     * @return bool true if successful, false otherwise
     */
    public function install() {
        // Checks if module IWmain is installed. If not returns error
        $modid = ModUtil::getIdFromName('IWmain');
        $modinfo = ModUtil::getInfo($modid);

        if ($modinfo['state'] != 3) {
            return LogUtil::registerError($this->__('Module IWmain is required. You have to install the IWmain module previously to install it.'));
        }

        // Check if the version needed is correct
        $versionNeeded = '3.0.0';
        if (!ModUtil::func('IWmain', 'admin', 'checkVersion', array('version' => $versionNeeded))) {
            return false;
        }

        // Name of the initial group
        $name = "changingRole";

        // The API function is called.
        $check = ModUtil::apiFunc('Groups', 'admin', 'getgidbyname', array('name' => $name));

        if ($check != false) {
            // Group already exists
            // LogUtil::registerError (_GROUPS_ALREADYEXISTS);
            $gid = $check;
        } else {
            // Falta mirar si existeix
            $gid = ModUtil::apiFunc('Groups', 'admin', 'create', array('name' => $name,
                        'gtype' => 0,
                        'state' => 0,
                        'nbumax' => 0,
                        'description' => $this->__('Initial group of users that can change the role')));
            // Success
        }

        // The return value of the function is checked here
        if ($gid != false) {
            $this->setVar('rolegroup', $gid);
            // Gets the first sequence number of permissions list
            $pos = DBUtil::selectFieldMax('group_perms', 'sequence', 'MIN');
            // SET MODULE AND BLOCK PERMISSIONS
            // insert permission myrole:: :: administration in second place
            ModUtil::apiFunc('permissions', 'admin', 'create', array('realm' => 0,
                'id' => $gid,
                'component' => 'IWmyrole::',
                'instance' => '::',
                'level' => '800',
                'insseq' => $pos + 1));
        }

        $this->setVar('groupsNotChangeable', '');

        //Initialation successfull
        return true;
    }
Exemplo n.º 2
0
    /**
     * Check if the group that can change roles have the correct permissions
     * @author:     Albert Pérez Monfort (aperezm@xtec.cat)
     * @param:	Array with the id of the group where the user will be enroled
     * @return:	True if success and false in other case
     */
    public function correctGroupPermissions($args) {
        // Security check
        if (!SecurityUtil::checkPermission('IWmyrole::', "::", ACCESS_ADMIN)) {
            throw new Zikula_Exception_Forbidden();
        }
        // Get the min sequence value
        $pos = DBUtil::selectFieldMax('group_perms', 'sequence', 'MIN') + 1;

        $pntable = & DBUtil::getTables();
        $c = $pntable['group_perms_column'];

        $where = "$c[gid] = " . ModUtil::getVar('IWmyrole', 'rolegroup') . " AND $c[component] = 'IWmyrole::' AND $c[level] = 800 AND $c[sequence] = $pos";
        // get the objects from the db
        $items = DBUtil::selectObjectArray('group_perms', $where);

        // Check for an error with the database code, and if so set an appropriate
        // error message and return
        if ($items === false) {
            return LogUtil::registerError($this->__('Error! Could not load items.'));
        }

        // Return the items
        return $items;
    }
Exemplo n.º 3
0
 /**
  * Get the maximum sequence number currently in a given table.
  *
  * @param string $args ['column'] the sequence column name.
  *
  * @return int the maximum sequence number.
  */
 public function maxsequence($args)
 {
     // Security check
     if (!SecurityUtil::checkPermission('Permissions::', '::', ACCESS_ADMIN)) {
         return LogUtil::registerPermissionError();
     }
     // Argument check
     if (!isset($args['column'])) {
         return LogUtil::registerArgsError();
     }
     return DBUtil::selectFieldMax('group_perms', $args['column']);
 }
Exemplo n.º 4
0
 /**
  * constructor
  */
 public function __construct()
 {
     $this->tablePrefix = System::getVar('prefix');
     $this->structureIndex = DBUtil::selectFieldMax('content_page', 'setRight');
 }
Exemplo n.º 5
0
 /**
  * Modify the categories, labels, custom fields
  */
 public function edit()
 {
     // Security check
     if (!SecurityUtil::checkPermission('AddressBook::', '::', ACCESS_ADMIN)) {
         return LogUtil::registerPermissionError();
     }
     $ot = FormUtil::getPassedValue('ot', 'categories', 'GET');
     $id = (int) FormUtil::getPassedValue('id', 0, 'GET');
     $class = 'AddressBook_DBObject_' . ucfirst($ot);
     if (!class_exists($class)) {
         return z_exit($this->__f('Error! Unable to load class [%s]', $ot));
     }
     $data = array();
     if ($id) {
         $object = new $class();
         $data = $object->get($id);
     } else {
         $data['id'] = 0;
     }
     $this->view->assign($ot, $data);
     if ($ot == "customfield") {
         $new_position = DBUtil::selectFieldMax('addressbook_customfields', 'position') + 1;
         $this->view->assign('new_position', $new_position);
     }
     return $this->view->fetch('admin_' . $ot . '_edit.tpl');
 }
Exemplo n.º 6
0
    /**
     * Utility function to get the weight limits.
     *
     * @return array|boolean Array of weight limits (min and max), or false on failure.
     */
    public function getweightlimits()
    {
        // Get datbase setup
        $dbtable = DBUtil::getTables();
        $column  = $dbtable['user_property_column'];

        $where = "WHERE {$column['prop_weight']} != 0";
        $max   = DBUtil::selectFieldMax('user_property', 'prop_weight', 'MAX', $where);

        $where = "WHERE {$column['prop_weight']} != 0";
        $min   = DBUtil::selectFieldMax('user_property', 'prop_weight', 'MIN', $where);

        // Return the number of items
        return array('min' => $min, 'max' => $max);
    }
Exemplo n.º 7
0
function mediashareGetNewPosition($albumId)
{
    $dom = ZLanguage::getModuleDomain('mediashare');
    $pntable = pnDBGetTables();
    $mediaColumn = $pntable['mediashare_media_column'];
    $where = "{$mediaColumn['parentAlbumId']} = {$albumId}";
    $max = DBUtil::selectFieldMax('mediashare_media', 'position', 'MAX', $where);
    if ($max === false) {
        return LogUtil::registerError(__f('Error in %1$s: %2$s.', array('editapi.mediashareGetNewPosition', 'Could not get the max position.'), $dom));
    }
    return empty($max) ? 0 : $max + 1;
}
Exemplo n.º 8
0
    public function reserva($args) {
        $sid = FormUtil::getPassedValue('sid', isset($args['sid']) ? $args['sid'] : null, 'GET');
        $start = FormUtil::getPassedValue('start', isset($args['start']) ? $args['start'] : null, 'GET');
        $end = FormUtil::getPassedValue('end', isset($args['end']) ? $args['end'] : null, 'GET');
        $group = FormUtil::getPassedValue('usrgroup', isset($args['usrgroup']) ? $args['usrgroup'] : null, 'GET');
        $user = FormUtil::getPassedValue('user', isset($args['user']) ? $args['user'] : null, 'GET');
        $reason = FormUtil::getPassedValue('reason', isset($args['reason']) ? $args['reason'] : null, 'GET');
        $nsessions = FormUtil::getPassedValue('nsessions', isset($args['nsessions']) ? $args['nsessions'] : null, 'GET');
        $nbooking = FormUtil::getPassedValue('nbooking', isset($args['nbooking']) ? $args['nbooking'] : null, 'GET');
        $admin = FormUtil::getPassedValue('admin', isset($args['admin']) ? $args['admin'] : null, 'GET');

        //Comprova que la identitat de l'espai de reserva efectivament hagi arribat
        if ((!isset($sid))) {
            return LogUtil::registerError($this->__('Error! Could not do what you wanted. Please check your input.'));
        }
        // Security check
        if (!SecurityUtil::checkPermission('IWbookings::', "::", ACCESS_ADD)) {
            return LogUtil::registerError($this->__('You are not allowed to administrate the bookings'), 403);
        }

        // Identificates grouped bookings: has the same day of week and time during n consecutive weeks
        $key = DBUtil::selectFieldMax('IWbookings', 'bid') + 1;
        if (empty($nbooking))
            $nbooking = $key;

        // Get day of week
        $dow = date("w", DateUtil::makeTimeStamp($start));
        ($dow == 0) ? $dow = 7 : "";
        ($admin) ? $temp = 1 : 0;
        $item = array('sid' => $sid,
            'user' => $user,
            'usrgroup' => $group,
            'start' => $start,
            'end' => $end,
            'reason' => $reason,
            'dayofweek' => $dow,
            'bkey' => $nbooking,
            'temp' => $temp);
        if (!DBUtil::insertObject($item, 'IWbookings', 'bid')) {
            LogUtil::registerError($this->__('Error! Creation attempt failed.'));
            return false;
        }

        // Return the id of the newly created item to the calling process
        return $nbooking;
    }