Example #1
0
    public function skipModules($args) {

        // Security check
        if (!SecurityUtil::checkPermission('IWstats::', '::', ACCESS_EDIT)) {
            throw new Zikula_Exception_Forbidden();
        }

        $table = DBUtil::getTables();
        $c = $table['IWstats_column'];
        $where = "1=1";
        $items = array('skippedModule' => 0);
        if (!DBUTil::updateObject($items, 'IWstats', $where)) {
            return LogUtil::registerError($this->__('Error! Update attempt failed.'));
        }

        $items = array('skippedModule' => 1);
        foreach ($args['moduleId'] as $module) {
            $where = "$c[moduleid] = $module";
            if (!DBUTil::updateObject($items, 'IWstats', $where)) {
                return LogUtil::registerError($this->__('Error! Update attempt failed.'));
            }
        }

        return true;
    }
Example #2
0
 /**
  * Update the agenda information in the database
  *
  * @param array $args Agenda identity and values
  *
  * @return True if success and false otherwise
  */
 public function editAgenda($args) {
     $daid = FormUtil::getPassedValue('daid', isset($args['daid']) ? $args['daid'] : null, 'POST');
     $items = FormUtil::getPassedValue('items', isset($args['items']) ? $args['items'] : null, 'POST');
     $sv = FormUtil::getPassedValue('sv', isset($args['sv']) ? $args['sv'] : null, 'POST');
     // Get agenda information
     $item = ModUtil::apiFunc('IWagendas', 'user', 'getAgenda', array('daid' => $daid));
     if ($item == false) {
         return LogUtil::registerError($this->__('Agenda not found'));
     }
     if (!ModUtil::func('IWmain', 'user', 'checkSecurityValue', array('sv' => $sv)) || !SecurityUtil::checkPermission('IWagendas::', "::", ACCESS_READ)) {
         // Security check
         $this->throwForbiddenUnless(SecurityUtil::checkPermission('IWagendas::', '::', ACCESS_ADMIN));
     }
     // Needed argument
     if (!isset($daid) || !is_numeric($daid)) {
         return LogUtil::registerError($this->__('Error! Could not do what you wanted. Please check your input.'));
     }
     $pntable = DBUtil::getTables();
     $c = $pntable['IWagendas_definition_column'];
     $where = "$c[daid] = $daid";
     if (!DBUTil::updateObject($items, 'IWagendas_definition', $where)) {
         return LogUtil::registerError($this->__('Error! Update attempt failed.'));
     }
     return true;
 }
Example #3
0
function mediashare_sourcesapi_OnOffsources($args)
{
    $dom = ZLanguage::getModuleDomain('mediashare');
    if ($args['id'] === false) {
        return false;
    }
    $source = DBUtil::selectObjectByID('mediashare_sources', $args['id']);
    if ($args['active'] === flase) {
        $source['active'] = 0;
    } else {
        $source['active'] = $args['active'];
        // todo turn off same mimeTypes
    }
    $result = DBUTil::updateObject($source, 'mediashare_sources');
    if ($result === false) {
        return LogUtil::registerError(__f('Error in %1$s: %2$s.', array('mediahandlerapi.addHandler', 'Could not change source status.'), $dom));
    }
    //turn off same mimeTypes
    return true;
}
Example #4
0
    /**
     * create the fields necessary for synchronization
     * @author:     Albert Pérez Monfort (aperezm@xtec.cat)
     * @param: 	id of the note, id of the form and ids of the needed fields
     * @return:	 True if success and false otherwise
     */
    public function fieldsToDelete($args) {

        $fid = (isset($args['fid'])) ? $args['fid'] : null;
        $fmid = (isset($args['fmid'])) ? $args['fmid'] : null;
        // Security check
        if (!SecurityUtil::checkPermission('IWforms::', "::", ACCESS_READ)) {
            throw new Zikula_Exception_Forbidden();
        }
        //check user access to this form
        $access = ModUtil::func('IWforms', 'user', 'access', array('fid' => $fid));
        if ($access['level'] < 7) {
            LogUtil::registerError($this->__('You can not access this form to view the annotations'));
            // Redirect to the main site for the user
            return System::redirect(ModUtil::url('IWforms', 'user', 'main'));
        }
        $noteContent = ModUtil::apiFunc('IWforms', 'user', 'getAllNoteContents', array('fid' => $fid,
                    'fmid' => $fmid));
        if (!$noteContent) {
            LogUtil::registerError($this->__('Note content not found'));
            return System::redirect(ModUtil::url('IWforms', 'user', 'manage', array('fid' => $fid,
                                'order' => $order,
                                'ipp' => $ipp,
                                'init' => $init,
                                'filterValue' => $filterValue,
                                'filter' => $filter)));
        }
        $fieldsIdsNoteArray = array();
        foreach ($noteContent as $noteContentId) {
            $fieldsIdsNoteArray[] = $noteContentId['fndid'];
        }
        //get form fields
        $fields = ModUtil::apiFunc('IWforms', 'user', 'getAllFormFields', array('fid' => $fid,
                    'whereArray' => 'active|1'));
        if (!$fields) {
            LogUtil::registerError($this->__('Note fields not found'));
            return System::redirect(ModUtil::url('IWforms', 'user', 'manage', array('fid' => $fid,
                                'order' => $order,
                                'ipp' => $ipp,
                                'init' => $init,
                                'filterValue' => $filterValue,
                                'filter' => $filter)));
        }
        foreach ($fields as $field) {
            if ($field['fieldType'] < 10) {
                $fieldsIdsArray[] = $field['fndid'];
            }
        }
        // get the fields that must be deleted
        $toDelete = array_diff($fieldsIdsNoteArray, $fieldsIdsArray);
        $pntable = DBUtil::getTables();
        $c = $pntable['IWforms_note_column'];
        foreach ($toDelete as $delete) {
            $where = "$c[fmid]=$fmid AND $c[fndid]=$delete";
            if (!DBUTil::deleteWhere('IWforms_note', $where)) {
                return LogUtil::registerError($this->__('Error! delete attempt failed during field synchronization.'));
            }
        }
        return false;
    }
Example #5
0
 public function reset_timeframe($id){
     // Seleccionar tots els espais que facin referència al marc $id i canviar el valor a 0
     $pntables = pnDBGetTables();
     $c = $pntables['IWbookings_spaces_column'];
     $obj = array('mdid' => 0);
     $where    = "WHERE $c[mdid]=".DataUtil::formatForStore($id);
     DBUTil::updateObject ($obj, 'IWbookings_spaces', $where);
 }
Example #6
0
    /**
     * Change user subscription to a forum
     * @author Josep Ferràndiz Farré (jferran6@xtec.cat)
     * @param fid forum id
     * @param action (IWforums_Constant::SUBSCRIBE, IWforums_Constant::UNSUBSCRIBE)
     * @version 3.1.0 
     * @date 04/03/2015
     */
                
    public function setSubscriptionState($args) {
        $uid = FormUtil::getPassedValue('uid', isset($args['uid']) ? $args['uid'] : UserUtil::getVar('uid'), 'GET');  
        $fid = FormUtil::getPassedValue('fid', isset($args['fid']) ? $args['fid'] : null, 'GET');  
        $action = FormUtil::getPassedValue('action', isset($args['action']) ? $args['action'] : null, 'GET');  

        $uid = isset($args['uid']) ? $args['uid'] : UserUtil::getVar('uid');  
        $fid = isset($args['fid']) ? $args['fid'] : null;  
        $action = isset($args['action']) ? $args['action'] : null;  
        
        $result = false;
        if (true) {//(isset($fid) && isset($action) && is_numeric($fid) && is_numeric($action)) {
            $sv = ModUtil::func('IWmain', 'user', 'genSecurityValue');
            $forum = ModUtil::apiFunc($this->name, 'user', 'get', array('fid' => $fid, 'sv' => $sv));
            switch ($action) {
                case IWforums_Constant::SUBSCRIBE:
                    // Check if forum allows subscription 
                    if ($forum['subscriptionMode'] == IWforums_Constant::VOLUNTARY){
                       // Add uid to subscribers field
                        if (strlen($forum['subscribers'])) 
                            $users = explode("$", $forum['subscribers']);
                        else {
                            $users = array();
                        }
                        // Verify uid isn't in subscribers list
                        if (!in_array($uid, $users)) {
                            // Add uid to subscriptors list
                            $users[] = $uid;
                            $subscribers = implode("$", $users);
                            // Update table
                            $pntable = DBUtil::getTables();
                            $c = $pntable['IWforums_definition_column'];
                            $where = "$c[fid]=$fid";
                            $item = array('subscribers' => $subscribers);
                            
                            $result =  (DBUTil::updateObject($item, 'IWforums_definition', $where)) ;
                        }
                    } elseif ($forum['subscriptionMode'] == IWforums_Constant::OPTIONAL){
                       // Remove uid from noSubscribers field 
                       if (strlen($forum['noSubscribers'])) 
                            $users = explode("$", $forum['noSubscribers']);
                        else {
                            $users = array();
                        }
                        // Verify uid isn't in subscribers list
                        if (in_array($uid, $users)) {
                            // Remove uid from noSubscriptors list
                            $remove[] = $uid;
                            //$nlist = array_diff($users, $remove);
                            $noSubscribers = implode("$", array_diff($users, $remove));
                            // Update table
                            $pntable = DBUtil::getTables();
                            $c = $pntable['IWforums_definition_column'];
                            $where = "$c[fid]=$fid";
                            $item = array('noSubscribers' => $noSubscribers);
                            
                            $result =  (DBUTil::updateObject($item, 'IWforums_definition', $where)) ;
                        }                   
                    }   
                    break;
                case IWforums_Constant::UNSUBSCRIBE:
                    // Check if forum allows unsubscription 
                    // Check if forum allows subscription 
                    if ($forum['subscriptionMode'] == IWforums_Constant::VOLUNTARY){
                       // Add uid to subscribers field
                        if (strlen($forum['subscribers'])) 
                            $users = explode("$", $forum['subscribers']);
                        else {
                            $users = array();
                        }
                        // Verify uid isn't in subscribers list
                        if (in_array($uid, $users)) {
                            // Remove uid from noSubscriptors list
                            $remove[] = $uid;
                            //$nlist = array_diff($users, $remove);
                            $subscribers = implode("$", array_diff($users, $remove));
                            // Update table
                            $pntable = DBUtil::getTables();
                            $c = $pntable['IWforums_definition_column'];
                            $where = "$c[fid]=$fid";
                            $item = array('subscribers' => $subscribers);
                            
                            $result =  (DBUTil::updateObject($item, 'IWforums_definition', $where)) ;
                        }                   
                    } elseif ($forum['subscriptionMode'] == IWforums_Constant::OPTIONAL){
                       // Remove uid from noSubscribers field 
                       if (strlen($forum['noSubscribers'])) 
                            $users = explode("$", $forum['noSubscribers']);
                        else {
                            $users = array();
                        }
                        // Verify uid isn't in subscribers list
                        if (!in_array($uid, $users)) {
                            // Add uid to subscriptors list
                            $users[] = $uid;
                            $noSubscribers = implode("$", $users);
                            // Update table
                            $pntable = DBUtil::getTables();
                            $c = $pntable['IWforums_definition_column'];
                            $where = "$c[fid]=$fid";
                            $item = array('noSubscribers' => $noSubscribers);
                            
                            $result =  (DBUTil::updateObject($item, 'IWforums_definition', $where)) ;
                        }                        
                    }   
                    break;
            }
        }
        return $result;        
    }
Example #7
0
    /**
     * Check if a user has begin an activity because he/she is created in users table
     * @author:     Albert Pérez Monfort (aperezm@xtec.cat)
     * @param:	args   Id of the user an id of the activity
     * @return:	true if user exists and false otherwise
     */
    public function submitValue($args) {
        $jid = FormUtil::getPassedValue('jid', isset($args['jid']) ? $args['jid'] : null, 'POST');
        $user_id = FormUtil::getPassedValue('user_id', isset($args['user_id']) ? $args['user_id'] : null, 'POST');
        $toDo = FormUtil::getPassedValue('toDo', isset($args['toDo']) ? $args['toDo'] : null, 'POST');
        $content = FormUtil::getPassedValue('content', isset($args['content']) ? $args['content'] : null, 'POST');

        // Security check
        if (!SecurityUtil::checkPermission('IWjclic::', "::", ACCESS_ADD)) {
            throw new Zikula_Exception_Forbidden();
        }

        // Needed argument
        if ($jid == null || !is_numeric($jid) || $user_id == null || !is_numeric($user_id)) {
            return LogUtil::registerError($this->__('Error! Could not do what you wanted. Please check your input.') . ' - ' . $jid . ' - ' . $user_id);
        }

        //get jclic activity
        $jclic = ModUtil::apiFunc('IWjclic', 'user', 'get', array('jid' => $jid));
        if ($jclic == false) {
            return LogUtil::registerError($this->__('Could not find the allocation requested'));
        }

        //Check if user can edit the activity because he/she is the owner or only change the expanded/collapsed status
        if ($jclic['user'] != UserUtil::getVar('uid')) {
            return LogUtil::registerError($this->__('You do not have access to edit the activity'));
        }

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

        $where = "$c[jid] = $jid AND $c[user_id] = $user_id";



        $items = array($toDo => $content);

        if (!DBUTil::updateObject($items, 'IWjclic_users', $where)) {
            return LogUtil::registerError($this->__('Error! Update attempt failed.'));
        }

        return true;
    }
Example #8
0
    /**
     * Update the users information
     * @author:     Albert Pérez Monfort (aperezm@xtec.cat)
     * @param:	args array with the users information
     * @return:	True if success and false otherwise
     */
    public function updateUser($args) {

        $uid = FormUtil::getPassedValue('uid', isset($args['uid']) ? $args['uid'] : null, 'POST');
        $nom = FormUtil::getPassedValue('nom', isset($args['nom']) ? $args['nom'] : null, 'POST');
        $cognom1 = FormUtil::getPassedValue('cognom1', isset($args['cognom1']) ? $args['cognom1'] : null, 'POST');
        $cognom2 = FormUtil::getPassedValue('cognom2', isset($args['cognom2']) ? $args['cognom2'] : null, 'POST');
        // Security check
        if (!SecurityUtil::checkPermission('IWusers::', '::', ACCESS_ADMIN)) {
            throw new Zikula_Exception_Forbidden();
        }
        //Needed arguments
        if (!isset($args['uid'])) {
            return LogUtil::registerError($this->__('Error! Could not do what you wanted. Please check your input.'));
        }
        foreach ($uid as $u) {
            $items = array('nom' => $nom[$u],
                'cognom1' => $cognom1[$u],
                'cognom2' => $cognom2[$u]);
            $table = DBUtil::getTables();
            $c = $table['IWusers_column'];
            $where = "$c[uid] = $u";
            if (!DBUTil::updateObject($items, 'IWusers', $where)) {
                return LogUtil::registerError($this->__('Error! Update attempt failed.'));
            }
        }
        return true;
    }
Example #9
0
    /**
     * Update a topic from the database
     * @author:     Albert Pï¿œrez Monfort (aperezm@xtec.cat)
     * @param:	args	The id of the topic and the information of the topic
     * @return:	true if success and false if fails
     */
    public function modificar($args) {
        $tid = FormUtil::getPassedValue('tid', isset($args['tid']) ? $args['tid'] : null, 'POST');
        $nomtema = FormUtil::getPassedValue('nomtema', isset($args['nomtema']) ? $args['nomtema'] : null, 'POST');
        $descriu = FormUtil::getPassedValue('descriu', isset($args['descriu']) ? $args['descriu'] : null, 'POST');
        $grup = FormUtil::getPassedValue('grup', isset($args['grup']) ? $args['grup'] : null, 'POST');

        // Security check
        if (!SecurityUtil::checkPermission('IWnoteboard::', '::', ACCESS_ADMIN)) {
            return LogUtil::registerPermissionError();
        }

        // Needed argument
        if (!isset($tid) || !isset($nomtema)) {
            return LogUtil::registerError($this->__('Error! Could not do what you wanted. Please check your input.'));
        }

        // Get the item
        $item = ModUtil::apiFunc('IWnoteboard', 'user', 'gettema', array('tid' => $tid));
        if (!$item) {
            return LogUtil::registerError($this->__('No such item found.'));
        }

        $items = array('nomtema' => $nomtema,
            'descriu' => $descriu,
            'grup' => $grup);

        $pntable = DBUtil::getTables();
        $c = $pntable['IWnoteboard_topics_column'];
        $where = "$c[tid]=$tid";

        if (!DBUTil::updateObject($items, 'IWnoteboard_topics', $where)) {
            return LogUtil::registerError($this->__('Error! Update attempt failed.'));
        }

        return true;
    }
Example #10
0
    /**
     * utility function to count the number of items held by this module
     *
     * @author	 Nathan Codding
     * @param 	 $args['userid'] userid to get private message count for
     * @return   integer   number of items held by this module
     */
    public function setreplied($args) {
        $msgid = FormUtil::getPassedValue('msgid', isset($args['msgid']) ? $args['msgid'] : null, 'POST');

        // Security check
        if (!SecurityUtil::checkPermission('IWmessages::', '::', ACCESS_OVERVIEW) || !UserUtil::isLoggedIn()) {
            return LogUtil::registerPermissionError();
        }

        // Argument check - make sure that all required arguments are present, if
        // not then set an appropriate error message and return
        if (!isset($msgid) || !is_numeric($msgid)) {
            return LogUtil::registerError($this->__('Error! Could not do what you wanted. Please check your input.'));
        }

        // Get the item
        $item = ModUtil::apiFunc('IWmessages', 'user', 'get', array('uid' => UserUtil::getVar('uid'),
                    'msgid' => $msgid));
        if (!$item) {
            return LogUtil::registerError($this->__('No such item found.'));
        }

        $items = array('replied' => 1);

        $pntable = DBUtil::getTables();
        $c = $pntable['IWmessages_column'];
        $where = "$c[msg_id]=$msgid";

        if (!DBUTil::updateObject($items, 'IWmessages', $where)) {
            return LogUtil::registerError($this->__('Error! Update attempt failed.'));
        }

        return true;
    }
Example #11
0
 /**
  * Mach a note with a flag
  * @author:     Albert Pérez Monfort (aperezm@xtec.cat)
  * @param:	args	The id of the note
  * 			The string of mached notes by the user
  * @return:	True if success and false otherwise
  */
 public function marca($args) {
     $nid = FormUtil::getPassedValue('nid', isset($args['nid']) ? $args['nid'] : null, 'POST');
     $marca = FormUtil::getPassedValue('marca', isset($args['marca']) ? $args['marca'] : null, 'POST');
     // Security check
     if (!SecurityUtil::checkPermission('IWnoteboard::', '::', ACCESS_READ)) {
         return LogUtil::registerPermissionError();
     }
     if (!UserUtil::isLoggedIn()) {
         LogUtil::registerError($this->__('You are not allowed to do this action'));
         return System::redirect(ModUtil::url('IWnoteboard', 'user', 'main'));
     }
     // Argument check
     if (!isset($nid) || !is_numeric($nid) || !isset($marca)) {
         return LogUtil::registerError($this->__('Error! Could not do what you wanted. Please check your input.'));
     }
     // Get the item
     $item = ModUtil::apiFunc('IWnoteboard', 'user', 'get', array('nid' => $nid));
     if (!$item) {
         return LogUtil::registerError($this->__('No such item found.'));
     }
     $item = array('marca' => $marca);
     $pntable = DBUtil::getTables();
     $c = $pntable['IWnoteboard_column'];
     $where = "$c[nid]=$nid";
     if (!DBUTil::updateObject($item, 'IWnoteboard', $where)) {
         return LogUtil::registerError($this->__('Error! Update attempt failed.'));
     }
     return true;
 }
Example #12
0
 public function setSubscriptionMode($args){
     $fid  = $this->request->getPost()->get('fid', '');
     $mode = $this->request->getPost()->get('mode', '');
     
     if (isset($fid) && $fid != 0 && isset($mode)) {
         $pntable = DBUtil::getTables();
         $c = $pntable['IWforums_definition_column'];
         $where = "$c[fid]=$fid";
         $item = array(
                     'fid' => $fid,
                     'subscriptionMode' => $mode);
         if (!DBUTil::updateObject($item, 'IWforums_definition', $where)) {
             return LogUtil::registerError($this->__('Error! Update attempt failed.'));
         }
     }       
     return $ftid;
 }
Example #13
0
 /**
  * Copy a form properties and fields
  * @author:     Albert Pérez Monfort (aperezm@xtec.cat)
  * @param:	args	The id of forum
  * @return:	true if success and false if fails
  */
 public function copy($args) {
     $fid = FormUtil::getPassedValue('fid', isset($args['fid']) ? $args['fid'] : null, 'POST');
     // Security check
     if (!SecurityUtil::checkPermission('IWforms::', '::', ACCESS_ADMIN)) {
         return LogUtil::registerPermissionError();
     }
     //Get item
     $item = ModUtil::apiFunc('IWforms', 'user', 'getFormDefinition', array('fid' => $fid));
     if ($item == false) {
         LogUtil::registerError($this->__('Could not find form'));
         return System::redirect(ModUtil::url('IWforms', 'admin', 'main'));
     }
     //Get all field information
     $fields = ModUtil::apiFunc('IWforms', 'user', 'getAllFormFields', array('fid' => $fid));
     if ($fields == false) {
         LogUtil::registerError($this->__('Could not find form fields, then it is not possible to copy the form'));
         return System::redirect(ModUtil::url('IWforms', 'admin', 'main'));
     }
     //copy form properties
     if (!DBUtil::insertObject($item, 'IWforms_definition', 'fid')) {
         return LogUtil::registerError($this->__('Error! Creation attempt failed.'));
     }
     //copy form fields
     foreach ($fields as $field) {
         $field['fid'] = $item['fid'];
         if (!DBUTil::insertObject($field, 'IWforms_note_definition', 'fndid')) {
             return LogUtil::registerError($this->__('Error! Creation attempt failed.'));
         }
     }
     // Return the id of the newly created item to the calling process
     return $item['fid'];
 }
Example #14
0
 public function esborra_membres($args) {
     //Comprovem que el paràmetre identitat hagi arribat
     if (!isset($args['gid'])) {
         return LogUtil::registerError($this->__('Error! Could not do what you wanted. Please check your input.'));
     }
     // Security check
     if (!SecurityUtil::checkPermission('IWgroups::', '::', ACCESS_ADMIN)) {
         throw new Zikula_Exception_Forbidden();
     }
     $table = DBUtil::getTables();
     $c = $table['group_membership_column'];
     //Esborrem el registre de la taula de membres dels grups
     foreach ($args['uid'] as $id) {
         $where = "$c[gid]=$args[gid] AND $c[uid]=$id";
         if (!DBUTil::deleteWhere('group_membership', $where)) {
             return LogUtil::registerError($this->__('An error has occurred while trying to delete a record from the data base'));
         }
     }
     //Repetim el procés per al grup de la dreta
     foreach ($args['uid1'] as $id) {
         $where = "$c[gid]=$args[gid1] AND $c[uid]=$id";
         if (!DBUTil::deleteWhere('group_membership', $where)) {
             return LogUtil::registerError($this->__('An error has occurred while trying to delete a record from the data base'));
         }
     }
     //Retornem true ja que el procés ha finalitzat amb èxit
     return true;
 }
Example #15
0
    /**
     * Update the time spended in the specified section 
     * @author Sara Arjona Téllez (sarjona@xtec.cat)
     * @param	args	array with the bean parameters
     * @return	XML with the result of the callback
     */
    public function beansavetime($args) {
        // Get the parameters
        extract($args);

        if (!($assignment = DBUtil::selectObjectByID('IWqv_assignments', $assignmentid, 'qvaid'))) {
            $error = "error_assignmentid_does_not_exist";
        } else {
            $pntable = DBUtil::getTables();
            $c = $pntable['IWqv_sections_column'];
            $where = " $c[qvaid]=$assignmentid AND $c[sectionid]='$sectionid' ";
            $section = DBUtil::selectObject('IWqv_sections', $where);
            if ($section) {
                //Update section
                $section['time'] = ModUtil::apiFunc('IWqv', 'user', 'addtime', array('time1' => $section[time],
                            'time2' => $sectiontime));
                if (!DBUTil::updateObject($section, 'IWqv_sections', $where)) {
                    $error = "error_db_update";
                }
            } else {
                // Insert section
                $section = array('qvaid' => $assignmentid,
                    'sectionid' => $sectionid,
                    'time' => $sectiontime);
                if (!DBUtil::insertObject($section, 'IWqv_sections', 'qvsid')) {
                    $error = "error_db_insert";
                }
            }
        }

        $response .= "<bean id=\"$beanid\" assignmentid=\"$assignmentid\">";
        $response .= " <section id=\"$sectionid\" ";
        if (isset($error))
            $response .= " error=\"$error\" ";
        $response .= " time=\"$section[time]\" />";
        $response .= '</bean>';
        return $response;
    }
Example #16
0
    /**
     * Subscribe multiple users into an agenda
     *
     * @param array $args The agenda identity and the users array to subscribe
     *
     * @return True if success and false otherwise
     */
    public function subsAltaMulti($args)
    {
        // Security check
        $this->throwForbiddenUnless(SecurityUtil::checkPermission('IWagendas::', '::', ACCESS_READ));

        $daid = FormUtil::getPassedValue('daid', isset($args['daid']) ? $args['daid'] : null, 'POST');
        $users = FormUtil::getPassedValue('users', isset($args['users']) ? $args['users'] : null, 'POST');

        // Needed argument
        if (!isset($daid) || $daid == 0 || !isset($users)) {
            return LogUtil::registerError($this->__('Error! Could not do what you wanted. Please check your input.'));
        }
        $agenda = ModUtil::apiFunc('IWagendas', 'user', 'getAgenda',
                                    array('daid' => $daid));
        if ($agenda == false) {
            return LogUtil::registerError($this->__('Event not found'));
        }
        // Check whether the user can access the agenda for this action
        $te_acces = ModUtil::func('IWagendas', 'user', 'te_acces',
                                   array('daid' => $daid));
        // If the user has no access, show an error message and stop execution
        if ($te_acces != 4) {
            return LogUtil::registerError($this->__('You are not allowed to administrate the agendas'));
        }
        $pntable = DBUtil::getTables();
        $c = $pntable['IWagendas_subs_column'];
        foreach ($users as $user) {
            $where = "$c[uid]=$user AND $c[daid]=$daid";
            $item = DBUtil::selectObjectArray('IWagendas_subs', $where, '', '-1', '-1', 'said');
            if (count($item) < 1) {
                $items = array('daid' => $daid,
                    'uid' => $user,
                    'donadabaixa' => '-2');
                if (!DBUtil::insertObject($items, 'IWagendas_subs', 'said')) {
                    $error = true;
                }
            } else {
                $items = array('donadabaixa' => '-2');
                if (!DBUTil::updateObject($items, 'IWagendas_subs', $where)) {
                    $error = true;
                }
            }
            if ($error) {
                return LogUtil::registerError($this->__('An error has occurred while updating the subscription to the agenda'));
            }
        }
        return true;
    }