/** * Updates a group in the database * * @param gid the group id. * @param gtype the group type. * @param state the group state. * @param nbumax the maximum of users. * @param name the group name. * @param description the group description. * * @return Zikula_Response_Ajax */ public function updategroup($args) { $this->checkAjaxToken(); $gid = $this->request->request->get('gid'); $gtype = $this->request->request->get('gtype', 9999); $state = $this->request->request->get('state'); $nbumax = $this->request->request->get('nbumax', 9999); $name = $this->request->request->get('name'); $description = $this->request->request->get('description'); $this->throwForbiddenUnless(SecurityUtil::checkPermission('Groups::', $gid . '::', ACCESS_EDIT)); if (empty($name)) { return new Zikula_Response_Ajax(array('result' => false, 'error' => true, 'gid' => $gid, 'message' => $this->__('Error! The group name is missing.'))); } if (preg_match("/[\n\r\t\x0B]/", $name)) { $name = trim(preg_replace("/[\n\r\t\x0B]/", "", $name)); } if (preg_match("/[\n\r\t\x0B]/", $description)) { $description = trim(preg_replace("/[\n\r\t\x0B]/", "", $description)); } // Pass to API $res = ModUtil::apiFunc('Groups', 'admin', 'update', array('gid' => $gid, 'name' => $name, 'gtype' => $gtype, 'state' => $state, 'nbumax' => $nbumax, 'description' => $description)); if ($res == false) { // check for sessionvar $msgs = LogUtil::getStatusMessagesText(); if (!empty($msgs)) { // return with msg, but not via Zikula_Exception_Fatal return new Zikula_Response_Ajax(array('result' => false, 'error' => true, 'gid' => $gid, 'message' => $msgs)); } } // Setting various defines $groupsCommon = new Groups_Helper_Common(); $typelabel = $groupsCommon->gtypeLabels(); $statelabel = $groupsCommon->stateLabels(); // Using uncached query here as it was returning the unupdated group $group = DBUtil::selectObjectByID('groups', $gid, 'gid', null, null, null, false); // get group member count $group['nbuser'] = ModUtil::apiFunc('Groups', 'user', 'countgroupmembers', array('gid' => $gid)); $group['statelbl'] = $statelabel[$group['state']]; $group['gtypelbl'] = $typelabel[$group['gtype']]; return new Zikula_Response_Ajax($group); }
/** * Encode data in JSON and return. * * This functions can add a new authid if requested to do so (default). * If the supplied args is not an array, it will be converted to an * array with 'data' as key. * Authid field will always be named 'authid'. Any other field 'authid' * will be overwritten! * Script execution stops here * * @param mixed $args String or array of data. * @param boolean $createauthid Create a new authid and send it back to the calling javascript. * @param boolean $xjsonheader Send result in X-JSON: header for prototype.js. * @param boolean $statusmsg Include statusmsg in output. * @param string $code Optional error code, default '200 OK'. * * @deprecated since 1.3.0 * * @return void */ public static function output($args, $createauthid = false, $xjsonheader = false, $statusmsg = true, $code = '200 OK') { if (!System::isLegacyMode()) { $response = new Zikula_Response_Ajax($args); echo $response; System::shutDown(); } // Below for reference - to be deleted. // check if an error message is set $msgs = LogUtil::getErrorMessagesText('<br />'); if ($msgs != false && !empty($msgs)) { self::error($msgs); } $data = !is_array($args) ? array('data' => $args) : $args; if ($statusmsg === true) { // now check if a status message is set $msgs = LogUtil::getStatusMessagesText('<br />'); $data['statusmsg'] = $msgs; } if ($createauthid === true) { $data['authid'] = SecurityUtil::generateAuthKey(ModUtil::getName()); } // convert the data to UTF-8 if not already encoded as such // Note: this isn't strict test but relying on the site language pack encoding seems to be a good compromise if (ZLanguage::getEncoding() != 'utf-8') { $data = DataUtil::convertToUTF8($data); } $output = json_encode($data); header("HTTP/1.0 $code"); header('Content-type: application/json'); if ($xjsonheader == true) { header('X-JSON:(' . $output . ')'); } echo $output; System::shutdown(); }