Example #1
0
 /**
  *  Constructor.
  *
  *  @param  object	The Group object to which this servey is associated.
  *  @param  int	        The servey_id.
  *  @param  array	The associative array of data.
  *  @return boolean	success.
  */
 function Survey(&$Group, $survey_id = false, $arr = false)
 {
     $this->Error();
     if (!$Group || !is_object($Group)) {
         $this->setError(sprintf(_('%1$s:: No Valid Group Object'), "Survey"));
         return false;
     }
     if ($Group->isError()) {
         $this->setError('Survey:: ' . $Group->getErrorMessage());
         return false;
     }
     $this->Group =& $Group;
     if ($survey_id) {
         if (!$arr || !is_array($arr)) {
             if (!$this->fetchData($survey_id)) {
                 return false;
             }
         } else {
             $this->data_array =& $arr;
             if ($this->data_array['group_id'] != $this->Group->getID()) {
                 $this->setError(_('Group_id in db result does not match Group Object'));
                 $this->data_array = null;
                 return false;
             }
         }
     }
     return true;
 }
 /**
  *	getProjectGroups - get an array of ProjectGroup objects.
  *
  *	@return	array	The array of ProjectGroups.
  */
 function &getProjectGroups()
 {
     if ($this->projectGroups) {
         return $this->projectGroups;
     }
     if (session_loggedin()) {
         $perm =& $this->Group->getPermission(session_get_user());
         if (!$perm || !is_object($perm) || !$perm->isMember()) {
             $public_flag = '=1';
             $exists = '';
         } else {
             $public_flag = '<3';
             if ($perm->isPMAdmin()) {
                 $exists = '';
             } else {
                 $exists = " AND group_project_id IN (SELECT role_setting.ref_id\n\t\t\t\t\tFROM role_setting, user_group\n\t\t\t\t\tWHERE role_setting.value::integer >= 0\n                                          AND role_setting.section_name = 'pm'\n                                          AND role_setting.ref_id=project_group_list_vw.group_project_id\n                                          \n   \t\t\t\t\t  AND user_group.role_id = role_setting.role_id\n\t\t\t\t\t  AND user_group.user_id='" . user_getid() . "') ";
             }
         }
     } else {
         $public_flag = '=1';
         $exists = '';
     }
     $sql = "SELECT *\n\t\t\tFROM project_group_list_vw\n\t\t\tWHERE group_id='" . $this->Group->getID() . "' \n\t\t\tAND is_public {$public_flag} {$exists}\n\t\t\tORDER BY group_project_id;";
     $result = db_query($sql);
     $rows = db_numrows($result);
     if (!$result || $rows < 1) {
         $this->setError(_('No ProjectGroups Found') . db_error());
         $this->projectGroups = NULL;
     } else {
         while ($arr = db_fetch_array($result)) {
             $this->projectGroups[] = new ProjectGroup($this->Group, $arr['group_project_id'], $arr);
         }
     }
     return $this->projectGroups;
 }
Example #3
0
 /**
  *	update - use this function to update an entry in the database.
  *
  *	@param	string	The name of the forum.
  *	@param	string	The description of the forum.
  *	@param	int		if it should be public (0) for private.
  *	@param	int	 	if we should allow non-logged-in users to post (0) for mandatory login.
  *	@param	string	The email address to send all new posts to.
  *	@param	int		if the messages that are posted in the forum should go to moderation before available. 0-> no moderation 1-> moderation for anonymous and non-project members 2-> moderation for everyone
  *	@return	boolean	success.
  */
 function update($forum_name, $description, $allow_anonymous, $is_public, $send_all_posts_to = '', $moderation_level = 0)
 {
     if (strlen($forum_name) < 3) {
         $this->setError(_('Forum Name Must Be At Least 3 Characters'));
         return false;
     }
     if (strlen($description) < 10) {
         $this->setError(_('Forum Description Must Be At Least 10 Characters'));
         return false;
     }
     if (eregi('[^_\\.0-9a-z-]', $forum_name)) {
         $this->setError(_('Illegal Characters in Forum Name'));
         return false;
     }
     if ($send_all_posts_to) {
         $invalid_mails = validate_emails($send_all_posts_to);
         if (count($invalid_mails) > 0) {
             $this->setInvalidEmailError();
             return false;
         }
     }
     if (!$this->userIsAdmin()) {
         $this->setPermissionDeniedError();
         return false;
     }
     $res = db_query("UPDATE forum_group_list SET\n\t\t\tforum_name='" . strtolower($forum_name) . "',\n\t\t\tdescription='" . htmlspecialchars($description) . "',\n\t\t\tsend_all_posts_to='" . $send_all_posts_to . "',\n\t\t\tallow_anonymous='" . $allow_anonymous . "',\n\t\t\tmoderation_level='" . $moderation_level . "',\n\t\t\tis_public='" . $is_public . "'\n\t\t\tWHERE group_id='" . $this->Group->getID() . "'\n\t\t\tAND group_forum_id='" . $this->getID() . "'");
     if (!$res || db_affected_rows($res) < 1) {
         $this->setError(_('Error On Update:') . ': ' . db_error());
         return false;
     }
     return true;
 }
Example #4
0
 /**
  * Merges rights for multiple group memebership or templates
  * @param object $userobj
  * @param array $groups
  */
 static function merge_rights($userobj, $groups, $primeObjects)
 {
     global $_zp_authority;
     $templates = false;
     $objects = $primeObjects;
     $custom = array();
     $oldgroups = $userobj->getGroup();
     $oldrights = $userobj->getRights();
     $oldobjects = $userobj->getObjects();
     $rights = 0;
     foreach ($groups as $key => $groupname) {
         if (empty($groupname)) {
             //	force the first template to happen
             $group = new Zenphoto_Administrator('', 0);
             $group->setName('template');
         } else {
             $group = Zenphoto_Authority::newAdministrator($groupname, 0, false);
         }
         if ($group->loaded) {
             if ($group->getName() == 'template') {
                 unset($groups[$key]);
                 if ($userobj->getID() > 0 && !$templates) {
                     //	fetch the existing rights and objects
                     $templates = true;
                     //	but only once!
                     $rights = $userobj->getRights();
                     $objects = $userobj->getObjects();
                 }
             }
             $rights = $group->getRights() | $rights;
             $objects = array_merge($group->getObjects(), $objects);
             $custom[] = $group->getCustomData();
         } else {
             unset($groups[$key]);
         }
     }
     $userobj->setCustomData(array_shift($custom));
     //	for now it is first come, first served.
     // unique objects
     $newobjects = array();
     foreach ($objects as $object) {
         $key = serialize(array('type' => $object['type'], 'data' => $object['data']));
         if (array_key_exists($key, $newobjects)) {
             if (array_key_exists('edit', $object)) {
                 $newobjects[$key]['edit'] = @$newobjects[$key]['edit'] | $object['edit'];
             }
         } else {
             $newobjects[$key] = $object;
         }
     }
     $objects = array();
     foreach ($newobjects as $object) {
         $objects[] = $object;
     }
     $userobj->setGroup($newgroups = implode(',', $groups));
     $userobj->setRights($rights);
     $userobj->setObjects($objects);
     $updated = $newgroups != $oldgroups || $oldobjects != $objects || empty($newgroups) && $rights != $oldrights;
     return $updated;
 }
 /**
  *	update - update a ProjectGroup in the database.
  *
  *	@param	string	The project name.
  *	@param	string	The project description.
  *	@param	string	The email address to send new notifications to.
  *	@return boolean success.
  */
 function update($project_name, $description, $send_all_posts_to = '')
 {
     if (strlen($project_name) < 3) {
         $this->setError(_('Title Must Be At Least 5 Characters'));
         return false;
     }
     if (strlen($description) < 10) {
         $this->setError(_('Document Description Must Be At Least 10 Characters'));
         return false;
     }
     if ($send_all_posts_to) {
         $invalid_mails = validate_emails($send_all_posts_to);
         if (count($invalid_mails) > 0) {
             $this->setInvalidEmailError();
             return false;
         }
     }
     if (!$this->userIsAdmin()) {
         $this->setPermissionDeniedError();
         return false;
     }
     $sql = "UPDATE project_group_list SET\n\t\t\tproject_name='" . htmlspecialchars($project_name) . "',\n\t\t\tdescription='" . htmlspecialchars($description) . "',\n\t\t\tsend_all_posts_to='{$send_all_posts_to}'\n\t\t\tWHERE group_id='" . $this->Group->getID() . "'\n\t\t\tAND group_project_id='" . $this->getID() . "'";
     $res = db_query($sql);
     if (!$res || db_affected_rows($res) < 1) {
         $this->setError('Error On Update: ' . db_error() . $sql);
         return false;
     }
     return true;
 }
 /**
  *  update - use this to update this ArtifactType in the database.
  *
  *  @param	string	The item name.
  *  @param	string	The item description.
  *  @param	bool	(1) true (0) false - whether to email on all updates.
  *  @param	string	The address to send new entries and updates to.
  *  @param	int		Days before this item is considered overdue.
  *  @param	int		Days before stale items time out.
  *  @param	bool	(1) true (0) false - whether the resolution box should be shown.
  *  @param	string	Free-form string that project admins can place on the submit page.
  *  @param	string	Free-form string that project admins can place on the browse page.
  *  @return true on success, false on failure.
  */
 function update($name, $description, $email_all, $email_address, $due_period, $status_timeout, $use_resolution, $submit_instructions, $browse_instructions)
 {
     if (!$this->userIsAdmin()) {
         $this->setPermissionDeniedError();
         return false;
     }
     if ($this->getDataType()) {
         $name = $this->getName();
         $description = $this->getDescription();
     }
     if (!$name || !$description || !$due_period || !$status_timeout) {
         $this->setError(_('ArtifactType: Name, Description, Due Period, and Status Timeout are required'));
         return false;
     }
     if ($email_address) {
         $invalid_emails = validate_emails($email_address);
         if (count($invalid_emails) > 0) {
             $this->SetError(_('E-mail address(es) appeared invalid') . ': ' . implode(',', $invalid_emails));
             return false;
         }
     }
     $email_all = !$email_all ? 0 : $email_all;
     $use_resolution = !$use_resolution ? 0 : $use_resolution;
     $sql = "UPDATE artifact_group_list SET \n\t\t\tname='" . htmlspecialchars($name) . "',\n\t\t\tdescription='" . htmlspecialchars($description) . "',\n\t\t\temail_all_updates='{$email_all}',\n\t\t\temail_address='{$email_address}',\n\t\t\tdue_period='" . $due_period * (60 * 60 * 24) . "',\n\t\t\tstatus_timeout='" . $status_timeout * (60 * 60 * 24) . "',\n\t\t\tsubmit_instructions='" . htmlspecialchars($submit_instructions) . "',\n\t\t\tbrowse_instructions='" . htmlspecialchars($browse_instructions) . "'\n\t\t\tWHERE \n\t\t\tgroup_artifact_id='" . $this->getID() . "' \n\t\t\tAND group_id='" . $this->Group->getID() . "'";
     $res = db_query($sql);
     if (!$res || db_affected_rows($res) < 1) {
         $this->setError('ArtifactType::Update(): ' . db_error());
         return false;
     } else {
         $this->fetchData($this->getID());
         return true;
     }
 }
 function &getArtifactQueries()
 {
     if (!is_null($this->ArtifactQueries)) {
         return $this->ArtifactQueries;
     }
     $this->ArtifactQueries = array();
     $res = db_query("SELECT * FROM artifact_query WHERE user_id='" . user_getid() . "' " . "AND group_artifact_id='" . $this->ArtifactType->getID() . "'");
     if (!$res) {
         $this->setError("ArtifactQueryFactory:: Database error");
     }
     while ($data = db_fetch_array($res)) {
         $artifactQuery = new ArtifactQuery($this->ArtifactType, $data["artifact_query_id"]);
         $this->ArtifactQueries[] = $artifactQuery;
     }
     return $this->ArtifactQueries;
 }
Example #8
0
 /**
  * Inserts a record into the table with nested sets
  *
  * @param  int $id
  * @param  array $data          
  * @return int
  */
 function appendSibling($id, $data = false, $dataId = false)
 {
     $id = intval($id);
     $dataId = intval($dataId);
     if (!is_array($data)) {
         $data = array();
     }
     if ($info = $this->getNodeInfo($id)) {
         $leftId = $info['left'];
         $rightId = $info['right'];
         $level = $info['level'];
         if (!$dataId) {
             // preparing data to be inserted
             foreach ($data as $n => $value) {
                 $sqlInsert[] = "{$n}='" . addslashes($value) . "'";
             }
             $sqlInsert = implode(', ', $sqlInsert);
             $sql = "INSERT INTO {$this->dataTable} SET {$sqlInsert}";
             // insert data
             $this->fDB->query($sql);
             $dataId = $this->fDB->getID();
         }
         // creating a place for the record being inserted
         $this->fDB->query("\n                    UPDATE {$this->structTable} \n                    SET\n                        `{$this->left}`  = IF(`{$this->left}`  > {$rightId}, `{$this->left}`+2,  `{$this->left}`),\n                        `{$this->right}` = IF(`{$this->right}` > {$rightId}, `{$this->right}`+2, `{$this->right}`)                         \n                    WHERE \n                        `{$this->right}` > {$rightId}\n                ");
         // insert structure
         $this->fDB->query("\n                    INSERT INTO {$this->structTable}\n                    SET                        \n                        `{$this->data_id}` = {$dataId},\n                        `{$this->left}`  = {$rightId}+1,\n                        `{$this->right}` = {$rightId}+2,\n                        `{$this->level}` = {$level}\n                ");
         $newId = $this->fDB->getID();
         return $newId;
     }
     $this->_displayError(NSTREE_ERROR_NODE_NOT_EXISTS, __LINE__, __FILE__, false);
     return false;
 }
 /**
  *	sendNotice - contains the logic for sending email/jabber updates.
  *
  *	@return	boolean	success.
  */
 function sendNotice($first = false)
 {
     global $send_task_email;
     if ($send_task_email === false) {
         return true;
     }
     $ids =& $this->getAssignedTo();
     //
     //	See if there is anyone to send messages to
     //
     if (count($ids) < 1 && !$this->ProjectGroup->getSendAllPostsTo()) {
         return true;
     }
     $body = "Task #" . $this->getID() . " has been updated. " . "\n\nProject: " . $this->ProjectGroup->Group->getPublicName() . "\nSubproject: " . $this->ProjectGroup->getName() . "\nSummary: " . util_unconvert_htmlspecialchars($this->getSummary()) . "\nComplete: " . $this->getPercentComplete() . "%" . "\nStatus: " . $this->getStatusName() . "\n\nDescription: " . util_unconvert_htmlspecialchars($this->getDetails());
     /*
     	Now get the followups to this task
     */
     $result2 = $this->getMessages();
     $rows = db_numrows($result2);
     if ($result2 && $rows > 0) {
         $body .= "\n\nFollow-Ups:";
         for ($i = 0; $i < $rows; $i++) {
             $body .= "\n\n-------------------------------------------------------";
             $body .= "\nDate: " . date(_('Y-m-d H:i'), db_result($result2, $i, 'postdate'));
             $body .= "\nBy: " . db_result($result2, $i, 'user_name');
             $body .= "\n\nComment:\n" . util_unconvert_htmlspecialchars(db_result($result2, $i, 'body'));
         }
     }
     $body .= "\n\n-------------------------------------------------------" . "\nFor more info, visit:" . "\n\n" . util_make_url('/pm/task.php?func=detailtask&project_task_id=' . $this->getID() . "&group_id=" . $this->ProjectGroup->Group->getID() . "&group_project_id=" . $this->ProjectGroup->getID());
     $subject = sprintf(_('[%1$s - %2$s] [Task #%3$d] '), $this->ProjectGroup->Group->getUnixName(), $this->ProjectGroup->getName(), $this->getID()) . util_unconvert_htmlspecialchars($this->getSummary());
     util_handle_message(array_unique($ids), $subject, $body, $this->ProjectGroup->getSendAllPostsTo());
     return true;
 }
 /**
  *	sendAttachNotice - contains the logic to send out email attachement followups when a message is posted.
  *
  *	@param int	attach_id	- The id of the file that has been attached
  *
  *	@return boolean success.
  */
 function sendAttachNotice($attach_id)
 {
     if ($attach_id) {
         $ids =& $this->Forum->getMonitoringIDs();
         //
         //	See if there is anyone to send messages to
         //
         if (!count($ids) > 0 && !$this->Forum->getSendAllPostsTo()) {
             return true;
         }
         $body = "\nRead and respond to this message at: " . "\n" . util_make_url('/forum/message.php?msg_id=' . $this->getID()) . "\nBy: " . $this->getPosterRealName() . "\n\n";
         $body .= "A file has been uploaded to this message, you can download it at: " . "\n" . util_make_url('/forum/attachment.php?attachid=' . $attach_id . "&group_id=" . $this->Forum->Group->getID() . "&forum_id=" . $this->Forum->getID()) . "\n\n";
         $body .= "\n\n______________________________________________________________________" . "\nYou are receiving this email because you elected to monitor this forum." . "\nTo stop monitoring this forum, login to " . $GLOBALS['sys_name'] . " and visit: " . "\n" . util_make_url('/forum/monitor.php?forum_id=' . $this->Forum->getID() . '&group_id=' . $this->Forum->Group->getID() . '&stop=1');
         $extra_headers = "Return-Path: <noreply@" . $GLOBALS['sys_default_domain'] . ">\n";
         $extra_headers .= "Errors-To: <noreply@" . $GLOBALS['sys_default_domain'] . ">\n";
         $extra_headers .= "Sender: <noreply@" . $GLOBALS['sys_default_domain'] . ">\n";
         $extra_headers .= "Reply-To: " . $this->Forum->getReturnEmailAddress() . "\n";
         $extra_headers .= "Precedence: Bulk\n" . "List-Id: " . $this->Forum->getName() . " <forum" . $this->Forum->getId() . "@" . $GLOBALS['sys_default_domain'] . ">\n" . "List-Help: " . util_make_url('/forum/forum.php?id=' . $this->Forum->getId()) . "\n" . "Message-Id: <forumpost" . $this->getId() . "@" . $GLOBALS['sys_default_domain'] . ">";
         $parentid = $this->getParentId();
         if (!empty($parentid)) {
             $extra_headers .= "\nIn-Reply-To: " . $this->Forum->getReturnEmailAddress() . "\n" . "References: <forumpost" . $this->getParentId() . "@" . $GLOBALS['sys_default_domain'] . ">";
         }
         $subject = "[" . $this->Forum->getUnixName() . "][" . $this->getID() . "] " . util_unconvert_htmlspecialchars($this->getSubject());
         if (count($ids) != 0) {
             $sql = "SELECT email FROM users WHERE status='A' AND user_id IN ('" . implode($ids, '\',\'') . "')";
             $bccres = db_query($sql);
         }
         ($BCC =& implode(util_result_column_to_array($bccres), ',')) . ',' . $this->Forum->getSendAllPostsTo();
         $User = user_get_object($this->getPosterID());
         util_send_message('', $subject, $body, "noreply@" . $GLOBALS['sys_default_domain'], $BCC, 'Forum', $extra_headers);
         return true;
     }
     return false;
 }
Example #11
0
 /**
  *  delete - delete this package and all its related data.
  *
  *  @param  bool	I'm Sure.
  *  @param  bool	I'm REALLY sure.
  *  @return   bool true/false;
  */
 function delete($sure, $really_sure)
 {
     if (!$sure || !$really_sure) {
         $this->setMissingParamsError();
         return false;
     }
     $perm =& $this->Group->getPermission(session_get_user());
     if (!$perm || !is_object($perm) || !$perm->isReleaseTechnician()) {
         $this->setPermissionDeniedError();
         return false;
     }
     $r =& $this->getReleases();
     for ($i = 0; $i < count($r); $i++) {
         if (!is_object($r[$i]) || $r[$i]->isError() || !$r[$i]->delete($sure, $really_sure)) {
             $this->setError('Release Error: ' . $r[$i]->getName() . ':' . $r[$i]->getErrorMessage());
             return false;
         }
     }
     $dir = $GLOBALS['sys_upload_dir'] . '/' . $this->Group->getUnixName() . '/' . $this->getFileName() . '/';
     // double-check we're not trying to remove root dir
     if (util_is_root_dir($dir)) {
         $this->setError('Package::delete error: trying to delete root dir');
         return false;
     }
     exec('rm -rf ' . $dir);
     db_query("DELETE FROM frs_package WHERE package_id='" . $this->getID() . "'\n\t\t\tAND group_id='" . $this->Group->getID() . "'");
     return true;
 }
 /**
  *  update - update a DocumentGroup.
  *
  *  @param	string	Name of the category.
  *  @return boolean.
  */
 function update($name, $parent_doc_group)
 {
     $perm =& $this->Group->getPermission(session_get_user());
     if (!$perm || !$perm->isDocEditor()) {
         $this->setPermissionDeniedError();
         return false;
     }
     if (!$name) {
         $this->setMissingParamsError();
         return false;
     }
     if ($parent_doc_group) {
         // check if parent group exists
         $res = db_query("SELECT * FROM doc_groups WHERE doc_group='{$parent_doc_group}' AND group_id=" . $this->Group->getID());
         if (!$res || db_numrows($res) < 1) {
             $this->setError(_('DocumentGroup: Invalid DocumentGroup parent ID'));
             return false;
         }
     } else {
         $parent_doc_group = 0;
     }
     $sql = "UPDATE doc_groups\n\t\t\tSET groupname='" . htmlspecialchars($name) . "',\n\t\t\tparent_doc_group='" . $parent_doc_group . "'\n\t\t\tWHERE doc_group='" . $this->getID() . "'\n\t\t\tAND group_id='" . $this->Group->getID() . "'";
     $result = db_query($sql);
     if ($result && db_affected_rows($result) > 0) {
         return true;
     } else {
         $this->setError(db_error());
         return false;
     }
 }
 function TaskBoardColumn($Taskboard, $arr = false)
 {
     $this->Error();
     if (!$Taskboard || !is_object($Taskboard)) {
         $this->setError('No Valid Taskboard Object');
         return false;
     }
     if ($Taskboard->isError()) {
         $this->setError('TaskBoardColumn: ' . $Taskboard->getErrorMessage());
         return false;
     }
     $this->Taskboard = $Taskboard;
     if (!$arr || !is_array($arr)) {
         if (!$this->fetchData($arr)) {
             return false;
         }
     } else {
         $this->data_array =& $arr;
         if ($this->data_array['taskboard_id'] != $this->Taskboard->getID()) {
             $this->setError('taskboard_id in db result does not match TaskBoard Object');
             $this->data_array = null;
             return false;
         }
     }
 }
Example #14
0
 /**
  *  getArtifacts - get an array of artifacts.
  *
  *  Retrieves an array of artifact objects.
  *
  *  @param	boolean	Database query offset.
  *  @return an array of artifact objects on success / false on failure.
  */
 function &getArtifacts($offset = false)
 {
     if (!$offset) {
         $offset = 0;
     }
     $sql = "SELECT \n\t\t\t\t\t* \n\t\t\t\tFROM \n\t\t\t\t\tartifact_vw \n\t\t\t\tWHERE \n\t\t\t\t\tgroup_artifact_id='" . $this->ArtifactType->getID() . "'";
     $res = db_query($sql, 500, $offset);
     if (!$res) {
         $this->setError('Could not get artifacts: ' . db_error());
         return false;
     } else {
         while ($rows = db_fetch_array($res)) {
             $this->artifacts_array[] = new Artifact($this->ArtifactType, $rows);
         }
         return $this->artifacts_array;
     }
 }
Example #15
0
 /**
  *  update - use this to update this ArtifactType in the database.
  *
  *  @param	string	The item name.
  *  @param	string	The item description.
  *  @param	int		Days before this item is considered overdue.
  *  @param	int		Days before stale items time out.
  *  @param	bool	(1) true (0) false - whether the resolution box should be shown.
  *  @param	string	Free-form string that project admins can place on the submit page.
  *  @param	string	Free-form string that project admins can place on the browse page.
  *  @param	bool	instantiate_for_new_projects (1) true (0) false - instantiate this tracker template for new projects
  *  @return true on success, false on failure.
  */
 function update($name, $description, $itemname, $allow_copy, $submit_instructions, $browse_instructions, $instantiate_for_new_projects)
 {
     global $Language;
     if (!$this->userIsAdmin()) {
         $this->setError('ArtifactType: ' . $Language->getText('tracker_common_canned', 'perm_denied'));
         return false;
     }
     if (!$name || !$description || !$itemname || trim($name) == "" || trim($description) == "" || trim($itemname) == "") {
         $this->setError('ArtifactType: ' . $Language->getText('tracker_common_type', 'name_requ'));
         return false;
     }
     if (!eregi("^[a-zA-Z0-9_]+\$", $itemname)) {
         $hp = Codendi_HTMLPurifier::instance();
         $this->setError($Language->getText('tracker_common_type', 'invalid_shortname', $hp->purify($itemname, CODENDI_PURIFIER_CONVERT_HTML)));
         return false;
     }
     $group_id = $this->Group->getID();
     $old_name = $this->getName();
     if ($old_name != $name) {
         $atf = new ArtifactTypeFactory($this->Group);
         if ($atf->isNameExists($name, $group_id)) {
             $this->setError($Language->getText('tracker_common_type', 'name_already_exists', $itemname));
             return false;
         }
     }
     $allow_copy = !$allow_copy ? 0 : $allow_copy;
     $instantiate_for_new_projects = !$instantiate_for_new_projects ? 0 : $instantiate_for_new_projects;
     $old_item_name = $this->getItemName();
     if ($old_item_name != $itemname) {
         $reference_manager = ReferenceManager::instance();
         if (!$reference_manager->checkKeyword($itemname)) {
             $this->setError($Language->getText('tracker_common_type', 'invalid_shortname', $itemname));
             return false;
         }
         if ($reference_manager->_isKeywordExists($itemname, $group_id)) {
             $this->setError($Language->getText('tracker_common_type', 'shortname_already_exists', $itemname));
             return false;
         }
         //Update table 'reference'
         $reference_dao = $this->getReferenceDao();
         $result = $reference_dao->update_keyword($old_item_name, $itemname, $this->Group->getID());
         //Update table 'cross_reference'
         $reference_dao = $this->getCrossReferenceDao();
         $result = $reference_dao->updateTargetKeyword($old_item_name, $itemname, $this->Group->getID());
         $result2 = $reference_dao->updateSourceKeyword($old_item_name, $itemname, $this->Group->getID());
     }
     //Update table 'artifact_group_list'
     $reference_dao = $this->getArtifactGroupListDao();
     $result = $reference_dao->updateArtifactGroupList($this->getID(), $this->Group->getID(), $name, $description, $itemname, $allow_copy, $submit_instructions, $browse_instructions, $instantiate_for_new_projects);
     if (!$result) {
         $this->setError('ArtifactType::Update(): ' . db_error());
         return false;
     } else {
         $this->fetchData($this->getID());
         return true;
     }
 }
Example #16
0
 /**
  *      fetchDataByGroup - re-fetch the data for this TaskBoard from the database by group ID.
  *
  *      @return boolean success.
  */
 function fetchDataByGroup()
 {
     $res = db_query_params('SELECT * FROM plugin_taskboard WHERE group_id=$1', array($this->Group->getID()));
     if (!$res || db_numrows($res) < 1) {
         $this->setError('TaskBoard is not configured for this group yet.');
         return false;
     }
     $this->data_array = db_fetch_array($res);
     db_free_result($res);
     return true;
 }
Example #17
0
 /**
  *  isSuperUser - whether the current user has site admin privilege.
  *
  *  @return	boolean	is_super_user.
  */
 function isSuperUser()
 {
     if (isset($this->is_site_admin)) {
         return $this->is_site_admin;
     }
     $res = db_query("SELECT count(*) AS count FROM user_group\n\t\t\tWHERE user_id='" . $this->User->getID() . "'\n\t\t\tAND group_id='1'\n\t\t\tAND admin_flags='A'");
     $row_count = db_fetch_array($res);
     $this->is_site_admin = $res && $row_count['count'] > 0;
     db_free_result($res);
     return $this->is_site_admin;
 }
 /**
  *  Exist - check if already exist a query with the same name , user_id and artifact_id
  *
  *  @return	boolean	exist
  */
 function Exist($name)
 {
     $user_id = user_getid();
     $art_id = $this->ArtifactType->getID();
     $sql = "SELECT * FROM artifact_query WHERE group_artifact_id = '{$art_id}' AND query_name = '{$name}' AND user_id = '{$user_id}'";
     $res = db_query($sql);
     if (db_numrows($res) > 0) {
         return true;
     } else {
         return false;
     }
 }
Example #19
0
 /**
  * Make a confirmation code and store it in the database
  *
  * @param object	$context The context bean
  * @param object	$bn	 A User bean
  * @param string	$kind
  *
  * @return string
  */
 private function makecode($context, $bn, $kind)
 {
     R::trashAll(R::find('confirm', 'user_id=?', array($bn->getID())));
     $code = hash('sha256', $bn->getID . $bn->email . $bn->login . uniqid());
     $conf = R::dispense('confirm');
     $conf->code = $code;
     $conf->issued = $context->utcnow();
     $conf->kind = $kind;
     $conf->user = $bn;
     R::store($conf);
     return $code;
 }
 /**
  *	create - create a new item in the database.
  *
  *	@param	string	Filename of the item.
  *	@param	string	Item filetype.
  *	@param	string	Item filesize.
  *	@param	binary	Binary item data.
  *	@param	string	Item description.
  *  @return id on success / false on failure.
  */
 function create($filename, $filetype, $filesize, $bin_data, $description = 'None')
 {
     // Some browsers don't supply mime type if they don't know it
     if (!$filetype) {
         // Let's be on safe side?
         $filetype = 'application/octet-stream';
     }
     //
     //	data validation
     //
     if (!$filename || !$filetype || !$filesize || !$bin_data) {
         //echo '<p>|'.$filename.'|'.$filetype.'|'.$filesize.'|'.$bin_data.'|';
         $this->setError(_('ArtifactFile: File name, type, size, and data are required'));
         return false;
     }
     if (session_loggedin()) {
         $userid = user_getid();
     } else {
         $userid = 100;
     }
     // If $filetype is "text/plain", $bin_data convert UTF-8 encoding.
     if (strcasecmp($filetype, "text/plain") === 0 && function_exists('mb_convert_encoding') && function_exists('mb_detect_encoding')) {
         $bin_data = mb_convert_encoding($bin_data, 'UTF-8', mb_detect_encoding($bin_data, "auto"));
         $filesize = strlen($bin_data);
     }
     db_begin();
     $res = db_query("INSERT INTO artifact_file\n\t\t\t(artifact_id,description,bin_data,filename,filesize,filetype,adddate,submitted_by)\n\t\t\tVALUES \n\t\t\t('" . $this->Artifact->getID() . "','{$description}','" . base64_encode($bin_data) . "','{$filename}',\n\t\t\t'{$filesize}','{$filetype}','" . time() . "','{$userid}')");
     $id = db_insertid($res, 'artifact_file', 'id');
     if (!$res || !$id) {
         db_rollback();
         $this->setError('ArtifactFile: ' . db_error());
         return false;
     } else {
         /*
         //
         //	skip this unless we need it later - save a db query
         //
         			//
         			//	Now set up our internal data structures
         			//
         			if (!$this->fetchData($id)) {
         				db_rollback();
         				return false;
         			}
         */
         db_commit();
         $this->Artifact->addHistory('File Added', $id . ': ' . $filename);
         $this->clearError();
         return $id;
     }
 }
 /**
  *       getMonitoredForums
  *
  *       @return Forum[] The array of Forums
  *
  */
 function getMonitoredForums()
 {
     $forums = array();
     $sql = "SELECT groups.group_name,groups.group_id,forum_group_list.group_forum_id,forum_group_list.forum_name " . "FROM groups,forum_group_list,forum_monitored_forums " . "WHERE groups.group_id=forum_group_list.group_id AND groups.status ='A' " . "AND forum_group_list.group_forum_id=forum_monitored_forums.forum_id " . "AND forum_monitored_forums.user_id='" . $this->User->getID() . "' ORDER BY group_name DESC";
     $result = db_query($sql);
     $rows = db_numrows($result);
     if ($rows < 1) {
         return $forums;
     }
     $last_group = '';
     for ($i = 0; $i < $rows; $i++) {
         $group_id = db_result($result, $i, 'group_id');
         $forum_id = db_result($result, $i, 'group_forum_id');
         $group =& group_get_object($group_id);
         $forum =& new Forum($group, $forum_id);
         if ($forum->isError()) {
             $this->setError($forum->getErrorMessage());
         } else {
             $forums[] =& $forum;
         }
     }
     return $forums;
 }
 /**
  *	getMailingLists - get an array of MailingList objects for this Group.
  *
  * @param boolean $admin if we are in admin mode (we want to see deleted lists)
  *	@return	array	The array of MailingList objects.
  */
 function &getMailingLists()
 {
     if (isset($this->mailingLists) && is_array($this->mailingLists)) {
         return $this->mailingLists;
     }
     $public_flag = MAIL__MAILING_LIST_IS_PUBLIC;
     $perm =& $this->Group->getPermission(session_get_user());
     if ($perm && is_object($perm) && $perm->isMember()) {
         $public_flag = MAIL__MAILING_LIST_IS_PRIVATE . ', ' . MAIL__MAILING_LIST_IS_PUBLIC;
     }
     $sql = 'SELECT * ' . 'FROM mail_group_list ' . 'WHERE group_id=\'' . $this->Group->getID() . '\' ' . 'AND is_public IN (' . $public_flag . ') ' . 'ORDER BY list_name;';
     $result = db_query($sql);
     if (!$result) {
         $this->setError(sprintf(_('Error Getting %1$s'), _('Error Getting %1$s')) . db_error());
         return false;
     } else {
         $this->mailingLists = array();
         while ($arr = db_fetch_array($result)) {
             $this->mailingLists[] = new MailingList($this->Group, $arr['group_list_id'], $arr);
         }
     }
     return $this->mailingLists;
 }
 /**
  *	update - use this function to update an entry in the database.
  *
  *	@param	string	The description of the mailing list
  *	@param	int	Pass (1) if it should be public (0) for private
  *	@return	boolean	success.
  */
 function update($description, $isPublic = MAIL__MAILING_LIST_IS_PUBLIC)
 {
     if (!$this->userIsAdmin()) {
         $this->setPermissionDeniedError();
         return false;
     }
     $sql = "UPDATE mail_group_list \n\t\t\tSET is_public='" . $isPublic . "', \n\t\t\tdescription='" . $description . "' \n\t\t\tWHERE group_list_id='" . $this->groupMailingListId . "' \n\t\t\tAND group_id='" . $this->Group->getID() . "'";
     $res = db_query($sql);
     if (!$res || db_affected_rows($res) < 1) {
         $this->setError(_('Error On Update:') . db_error());
         return false;
     }
     return true;
 }
Example #24
0
 /**
  *	create - create a new item in the database.
  *
  *	@para	string	Filename of the item.
  *	@param	string	Item filetype.
  *	@param	string	Item filesize.
  *	@param	binary	Binary item data.
  *	@param	string	Item description.
  *  @return id on success / false on failure.
  */
 function create($filename, $filetype, $filesize, $bin_data, $description = false, &$changes)
 {
     global $Language;
     if (!$description) {
         $description = $Language->getText('global', 'none');
     }
     $old_value = $this->Artifact->getAttachedFileNames();
     // Some browsers don't supply mime type if they don't know it
     if (!$filetype) {
         // Let's be on safe side?
         $filetype = 'application/octet-stream';
     }
     //
     //	data validation
     //
     if (!$filename || !$filetype || !$filesize || !$bin_data) {
         $GLOBALS['Response']->addFeedback('error', '<P>|' . $filename . '|' . $filetype . '|' . $filesize . '|' . $bin_data . '|');
         $this->setError('ArtifactFile: ' . $Language->getText('tracker_common_file', 'name_requ'));
         return false;
     }
     if (user_isloggedin()) {
         $userid = user_getid();
     } else {
         $userid = 100;
     }
     $res = db_query("INSERT INTO artifact_file\n\t\t\t(artifact_id,description,bin_data,filename,filesize,filetype,adddate,submitted_by)\n\t\t\tVALUES \n\t\t\t('" . db_ei($this->Artifact->getID()) . "','" . db_es($description) . "','','" . db_es($filename) . "',\n\t\t\t'" . db_ei($filesize) . "','" . db_es($filetype) . "','" . time() . "','" . db_ei($userid) . "')");
     $id = db_insertid($res, 'artifact_file', 'id');
     if (!$res || !$id) {
         $this->setError('ArtifactFile: ' . db_error());
         return false;
     } else {
         $this->clearError();
         $this->createOnFileSystem($id, $bin_data);
         $changes['attach']['description'] = $description;
         $changes['attach']['name'] = $filename;
         $changes['attach']['size'] = $filesize;
         if ($old_value == '') {
             $new_value = $filename;
         } else {
             $new_value = $old_value . "," . $filename;
         }
         $this->Artifact->addHistory('attachment', $old_value, $new_value);
         $changes['attach']['href'] = get_server_url() . "/tracker/download.php?artifact_id=" . $this->Artifact->getID() . "&id={$id}";
         return $id;
     }
 }
Example #25
0
 /**
  * Compute recursively all parsed definition tags 
  * and send them to callback methods (according to $this->_tagsCallBack)
  *
  * @param multidimentionnal array $definition : the XML tags definition to compute
  * @param integer $level : the current level of recursion (default : 0)
  * @return string the PHP / HTML content computed
  */
 function computeTags($definition, $level = 0)
 {
     $code = '';
     if (is_array($definition) && is_array($definition[0])) {
         //loop on subtags
         foreach (array_keys($definition) as $key) {
             if (isset($definition[$key]['nodename']) && $this->_isWanted($definition[$key]) && !isset($definition[$key]['childrens'])) {
                 $className = isset($this->_tagsCallback[$definition[$key]['nodename']]) ? $this->_tagsCallback[$definition[$key]['nodename']] : 'CMS_XMLTag';
                 if (!class_exists($className)) {
                     $this->raiseError('Unknown class ' . $className . '. Cannot compute tag ' . $definition[$key]['nodename']);
                     return false;
                 }
                 $xmlTag = new $className($definition[$key]['nodename'], $definition[$key]['attributes'], array(), array('context' => CMS_XMLTag::HTML_CONTEXT));
                 $xml = array($definition[$key]);
                 $code .= $this->treatWantedTag($xmlTag);
             } elseif (isset($definition[$key]['childrens'])) {
                 $computedChildren = $this->computeTags($definition[$key]['childrens'], ++$level);
                 unset($definition[$key]['childrens']);
                 $definition[$key]['childrens'][0]['textnode'] = $computedChildren;
                 $xml = array($definition[$key]);
                 if (isset($definition[$key]['nodename']) && $this->_isWanted($definition[$key])) {
                     $className = isset($this->_tagsCallback[$definition[$key]['nodename']]) ? $this->_tagsCallback[$definition[$key]['nodename']] : 'CMS_XMLTag';
                     if (!class_exists($className)) {
                         $this->raiseError('Unknown class ' . $className . '. Cannot compute tag ' . $definition[$key]['nodename']);
                         return false;
                     }
                     $xmlTag = new $className($definition[$key]['nodename'], $definition[$key]['attributes'], $definition[$key]['childrens'], array('context' => CMS_XMLTag::HTML_CONTEXT, 'childrenCallback' => array($this, 'computeTags')));
                     $code .= $this->treatWantedTag($xmlTag);
                 } else {
                     //append computed tags as code
                     $code .= $this->_parser->toXML($xml, false, isset($this->_treatmentParameters['replaceVars']) && $this->_treatmentParameters['replaceVars'] == true);
                 }
             } else {
                 //append text node
                 $xml = array($definition[$key]);
                 $code .= $this->_parser->toXML($xml, false, isset($this->_treatmentParameters['replaceVars']) && $this->_treatmentParameters['replaceVars'] == true);
             }
         }
     }
     if (is_a($this->_treatedObject, 'CMS_page') && isset($this->_treatmentParameters['replaceVars']) && $this->_treatmentParameters['replaceVars'] == true) {
         $code = str_replace('{{pageID}}', $this->_treatedObject->getID(), $code);
     }
     return $code;
 }
 /**
  *  update - update an ArtifactCanned message.
  *
  *  @param	string	Title of the message.
  *  @param	string	Body of the message.
  *  @return	boolean	success.
  */
 function update($title, $body)
 {
     if (!$this->ArtifactType->userIsAdmin()) {
         $this->setPermissionDeniedError();
         return false;
     }
     if (!$title || !$body) {
         $this->setMissingParamsError();
         return false;
     }
     $sql = "UPDATE artifact_canned_responses \n\t\t\tSET title='" . htmlspecialchars($title) . "',body='" . htmlspecialchars($body) . "'\n\t\t\tWHERE group_artifact_id='" . $this->ArtifactType->getID() . "' AND id='" . $this->getID() . "'";
     $result = db_query($sql);
     if ($result && db_affected_rows($result) > 0) {
         return true;
     } else {
         $this->setError(db_error());
         return false;
     }
 }
 /**
  *	Generate an alias for this field. The alias can be entered by the user or
  *	be generated automatically from the name of the field.
  *	@param	string	Alias entered by the user
  *	@param	string	Name of the field entered by the user (it'll be used when $alias is empty)
  *	@return	string
  */
 function generateAlias($alias, $name)
 {
     $alias = strtolower(trim($alias));
     if (strlen($alias) == 0) {
         // no alias was entered, generate alias from $name
         $name = strtolower(trim($name));
         // Convert the original name to a valid alias (i.e., if the extra field is
         // called "Quality test", make an alias called "quality_test").
         // The alias can be seen as a "unix name" for this field
         $alias = preg_replace("/ /", "_", $name);
         $alias = preg_replace("/[^[:alnum:]_]/", "", $alias);
         $alias = strtolower($alias);
     } elseif (!$this->validateAlias($alias)) {
         // alias is invalid...
         return false;
     }
     // check if the name conflicts with another alias in the same artifact type
     // in that case append a serial number to the alias
     $serial = 1;
     $conflict = false;
     do {
         $sql = "SELECT * FROM artifact_extra_field_list " . "WHERE LOWER(alias)='" . $alias . "' AND " . "group_artifact_id=" . $this->ArtifactType->getID();
         if ($this->data_array['extra_field_id']) {
             $sql .= " AND extra_field_id <> " . $this->data_array['extra_field_id'];
         }
         $res = db_query($sql);
         if (!$res) {
             $this->setError(db_error());
             return false;
         } else {
             if (db_numrows($res) > 0) {
                 // found another field with the same alias
                 $conflict = true;
                 $serial++;
                 $alias = $alias . $serial;
             } else {
                 $conflict = false;
             }
         }
     } while ($conflict);
     // at this point, the alias is valid and unique
     return $alias;
 }
 /**
  *	create - create a new row in the table used to store the 
  *	choices for selection boxes.  This function is only used for 
  *	extra fields and boxes configured by the admin
  *
  *	@param	string		Name of the choice
  *	@param	int		Id the box that contains the choice.
  *  @param  int status_id - optional for status box - maps to either open/closed.
  *  @return 	true on success / false on failure.
  */
 function create($name, $status_id = 0)
 {
     //
     //	data validation
     //
     if (trim($name) == '') {
         $this->setError(_('an element name is required'));
         return false;
     }
     if ($status_id) {
         if ($status_id == 1) {
         } else {
             $status_id = 2;
         }
     } else {
         $status_id = 0;
     }
     if (!$this->ArtifactExtraField->ArtifactType->userIsAdmin()) {
         $this->setPermissionDeniedError();
         return false;
     }
     $sql = "INSERT INTO artifact_extra_field_elements (extra_field_id,element_name,status_id) \n\t\t\tVALUES ('" . $this->ArtifactExtraField->getID() . "','" . htmlspecialchars($name) . "','{$status_id}')";
     db_begin();
     $result = db_query($sql);
     if ($result && db_affected_rows($result) > 0) {
         $this->clearError();
         $id = db_insertid($result, 'artifact_extra_field_elements', 'element_id');
         //
         //	Now set up our internal data structures
         //
         if (!$this->fetchData($id)) {
             db_rollback();
             return false;
         } else {
             db_commit();
             return $id;
         }
     } else {
         $this->setError(db_error());
         db_rollback();
         return false;
     }
 }
 /**
  *  update - update a ProjectCategory.
  *
  *  @param	string	Name of the category.
  *  @return	boolean success.
  */
 function update($name)
 {
     $perm =& $this->ProjectGroup->Group->getPermission(session_get_user());
     if (!$perm || !$perm->isPMAdmin()) {
         $this->setPermissionDeniedError();
         return false;
     }
     if (!$name) {
         $this->setMissingParamsError();
         return false;
     }
     $sql = "UPDATE project_category \n\t\t\tSET category_name='" . htmlspecialchars($name) . "'\n\t\t\tWHERE category_id='" . $this->getID() . "' \n\t\t\tAND group_project_id='" . $this->ProjectGroup->getID() . "'";
     $result = db_query($sql);
     if ($result && db_affected_rows($result) > 0) {
         return true;
     } else {
         $this->setError(db_error());
         return false;
     }
 }
 /**
  *  update - update an ArtifactCanned message.
  *
  *  @param	string	Title of the message.
  *  @param	string	Body of the message.
  *  @return	boolean	success.
  */
 function update($title, $body)
 {
     global $Language;
     if (!$this->ArtifactType->userIsAdmin()) {
         $this->setError($Language->getText('tracker_common_canned', 'perm_denied'));
         return false;
     }
     if (!$title || !$body) {
         $this->setError($Language->getText('tracker_common_canned', 'missing_param'));
         return false;
     }
     $sql = "UPDATE artifact_canned_responses \n\t\t\tSET title='" . db_es(htmlspecialchars($title)) . "',body='" . db_es(htmlspecialchars($body)) . "'\n\t\t\tWHERE group_artifact_id='" . db_ei($this->ArtifactType->getID()) . "' AND artifact_canned_id='" . db_ei($this->getID()) . "'";
     $result = db_query($sql);
     if ($result && db_affected_rows($result) > 0) {
         return true;
     } else {
         $this->setError(db_error());
         return false;
     }
 }