[evolvis-commits] r8038: adding some pieces for the new doc mgr↵?==?UTF-8?Q?
mirabilos at evolvis.org
mirabilos at evolvis.org
Thu Feb 24 15:55:46 CET 2011
Author: mirabilos
Date: 2011-02-24 15:55:46 +0100 (Thu, 24 Feb 2011)
New Revision: 8038
Added:
trunk/gforge_base/evolvisforge-5.1/gforge/common/docman/
trunk/gforge_base/evolvisforge-5.1/gforge/common/docman/Document.class
trunk/gforge_base/evolvisforge-5.1/gforge/db/docman-rewrite.sql
Log:
adding some pieces for the new doc mgr
Added: trunk/gforge_base/evolvisforge-5.1/gforge/common/docman/Document.class
===================================================================
--- trunk/gforge_base/evolvisforge-5.1/gforge/common/docman/Document.class (rev 0)
+++ trunk/gforge_base/evolvisforge-5.1/gforge/common/docman/Document.class 2011-02-24 14:55:46 UTC (rev 8038)
@@ -0,0 +1,288 @@
+<?php
+/**
+ * GForge Doc Mgr Facility
+ *
+ * Copyright 2002 GForge, LLC
+ * http://gforge.org/
+ *
+ * @version $Id$
+ */
+
+
+/*
+ Document Manager
+
+ by Quentin Cregan, SourceForge 06/2000
+
+ Complete OO rewrite by Tim Perdue 1/2003
+*/
+
+require_once('common/include/Error.class');
+
+class Document extends Error {
+
+ /**
+ * Associative array of data from db.
+ *
+ * @var array $data_array
+ */
+ var $data_array;
+
+ /**
+ * The Group object.
+ *
+ * @var object $Group
+ */
+ var $Group; //group object
+
+ /**
+ * Constructor.
+ *
+ * @param object The Group object to which this forum is associated.
+ * @param int The docid.
+ * @param array The associative array of data.
+ */
+ function Document(&$Group, $docid=false, $arr=false) {
+ $this->Error();
+ if (!$Group || !is_object($Group)) {
+ $this->setError('Document:: No Valid Group Object');
+ return false;
+ }
+ if ($Group->isError()) {
+ $this->setError('Document:: '.$Group->getErrorMessage());
+ return false;
+ }
+ $this->Group =& $Group;
+
+ if ($docid) {
+ if (!$arr || !is_array($arr)) {
+ if (!$this->fetchData($docid)) {
+ 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;
+ }
+ }
+ if (!$this->isPublic()) {
+ $perm =& $this->Group->getPermission( session_get_user() );
+
+ if (!$perm || !is_object($perm) || !$perm->isMember()) {
+ $this->setError('Permission Denied');
+ $this->data_array = null;
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+
+ function create($forum_name,$description,$is_public=1,$send_all_posts_to='',$create_default_message=1,$allow_anonymous=1) {
+
+ if (strlen($forum_name) < 3) {
+ $this->setError('Document Name Must Be At Least 3 Characters');
+ return false;
+ }
+ if (strlen($description) < 10) {
+ $this->setError('Document Description Must Be At Least 10 Characters');
+ return false;
+ }
+ if ($send_all_posts_to && !validate_email($send_all_posts_to)) {
+ $this->setError('Invalid Email Address');
+ return false;
+ }
+
+ // This is a hack to allow non-site-wide-admins to post
+ // news. The news/submit.php checks for proper permissions.
+ // This needs to be revisited.
+ global $sys_news_group;
+ if ($this->Group->getID() == $sys_news_group) {
+ // Future check will be added.
+
+ } else {
+ // Current permissions check.
+
+ $perm =& $this->Group->getPermission( session_get_user() );
+
+ if (!$perm || !is_object($perm) || !$perm->isDocumentAdmin()) {
+ $this->setError('Permission Denied');
+ return false;
+ }
+ }
+
+ $sql="INSERT INTO forum_group_list (group_id,forum_name,is_public,description,send_all_posts_to,allow_anonymous)
+ VALUES ('".$this->Group->getId()."',
+ '". htmlspecialchars($forum_name) ."',
+ '$is_public',
+ '". htmlspecialchars($description) ."',
+ '$send_all_posts_to',
+ '$allow_anonymous')";
+
+ db_begin();
+ $result=db_query($sql);
+ if (!$result) {
+ db_rollback();
+ $this->setError('Error Adding Document: '.db_error());
+ return false;
+ }
+ $this->docid=db_insertid($result,'forum_group_list','docid');
+ $this->fetchData($this->docid);
+
+ if ($create_default_message) {
+ $fm=new DocumentMessage($this);
+ if (!$fm->create('Welcome To '.$forum_name,'Welcome To '.$forum_name)) {
+ $this->setError($fm->getErrorMessage());
+ return false;
+//Error check?
+ }
+ }
+ db_commit();
+ return true;
+ }
+
+ /**
+ * fetchData() - re-fetch the data for this ArtifactType from the database
+ *
+ * @param int The artifact type ID
+ * @return true/false
+ */
+ function fetchData($docid) {
+ $res=db_query("SELECT * FROM docdata_vw
+ WHERE docid='$docid'
+ AND group_id='". $this->Group->getID() ."'");
+ if (!$res || db_numrows($res) < 1) {
+ $this->setError('Document:: Invalid docid');
+ return false;
+ }
+ $this->data_array =& db_fetch_array($res);
+ db_free_result($res);
+ return true;
+ }
+
+ /**
+ * getGroup - get the Group object this ArtifactType is associated with.
+ *
+ * @return Object The Group object.
+ */
+ function &getGroup() {
+ return $this->Group;
+ }
+
+ /**
+ * getID - get this docid.
+ *
+ * @return int The docid.
+ */
+ function getID() {
+ return $this->data_array['docid'];
+ }
+
+ /**
+ * getName - get the name of this document.
+ *
+ * @return string The name of this document.
+ */
+ function getName() {
+ return $this->data_array['filename'];
+ }
+
+ /**
+ * getDescription - the description of this document.
+ *
+ * @return string The description.
+ */
+ function getDescription() {
+ return $this->data_array['description'];
+ }
+
+ /**
+ * isPublic - whether this document is available to the general public.
+ *
+ * @return boolean public_status.
+ */
+ function isPublic() {
+ return (($this->data_array['stateid'] == 1) ? true : false);
+ }
+
+ /**
+ * getStateID - get this stateid.
+ *
+ * @return int The stateid.
+ */
+ function getStateID() {
+ return $this->data_array['stateid'];
+ }
+
+ /**
+ * getStateName - the statename of this document.
+ *
+ * @return string The statename.
+ */
+ function getStateName() {
+ return $this->data_array['state_name'];
+ }
+
+ /**
+ * getDocGroupID - get this doc_group_id.
+ *
+ * @return int The doc_group_id.
+ */
+ function getDocGroupID() {
+ return $this->data_array['doc_group'];
+ }
+
+ /**
+ * getDocGroupName - the doc_group_name of this document.
+ *
+ * @return string The docgroupname.
+ */
+ function getDocGroupName() {
+ return $this->data_array['group_name'];
+ }
+
+
+
+ function update($forum_name,$description,$is_public=1,$send_all_posts_to='',$allow_anonymous=0) {
+
+ if (strlen($forum_name) < 3) {
+ $this->setError('Document Name Must Be At Least 3 Characters');
+ return false;
+ }
+ if (strlen($description) < 10) {
+ $this->setError('Document Description Must Be At Least 10 Characters');
+ return false;
+ }
+ if ($send_all_posts_to && !validate_email($send_all_posts_to)) {
+ $this->setError('Invalid Email Address');
+ return false;
+ }
+
+ $perm =& $this->Group->getPermission( session_get_user() );
+
+ if (!$perm || !is_object($perm) || !$perm->isDocAdmin()) {
+ $this->setError('Permission Denied');
+ return false;
+ }
+
+ $res=db_query("UPDATE forum_group_list SET
+ forum_name='". htmlspecialchars($forum_name) ."',
+ description='". htmlspecialchars($description) ."',
+ is_public='$is_public',
+ send_all_posts_to='$send_all_posts_to',
+ allow_anonymous='$allow_anonymous'
+ WHERE group_id='".$this->Group->getID()."'
+ AND docid='".$this->getID()."'");
+
+ if (!$res || db_affected_rows($res) < 1) {
+ $this->setError('Error On Update: '.db_error());
+ return false;
+ }
+ return true;
+ }
+
+}
+
+?>
Added: trunk/gforge_base/evolvisforge-5.1/gforge/db/docman-rewrite.sql
===================================================================
--- trunk/gforge_base/evolvisforge-5.1/gforge/db/docman-rewrite.sql (rev 0)
+++ trunk/gforge_base/evolvisforge-5.1/gforge/db/docman-rewrite.sql 2011-02-24 14:55:46 UTC (rev 8038)
@@ -0,0 +1,35 @@
+--
+-- Add a group_id column to relate docs to a group
+--
+ALTER TABLE doc_data ADD COLUMN group_id INT;
+UPDATE doc_data SET group_id=(SELECT group_id FROM doc_groups WHERE doc_group=doc_data.doc_group);
+--
+-- Add fkey constraints
+--
+ALTER TABLE doc_data ADD CONSTRAINT docdata_groupid
+ FOREIGN KEY (group_id) REFERENCES groups(group_id) ON DELETE CASCADE;
+ALTER TABLE doc_data ADD CONSTRAINT docdata_docgroupid
+ FOREIGN KEY (doc_group) REFERENCES doc_groups(doc_group);
+ALTER TABLE doc_data ADD CONSTRAINT docdata_stateid
+ FOREIGN KEY (stateid) REFERENCES doc_states(stateid);
+ALTER TABLE doc_groups ADD CONSTRAINT docgroups_groupid
+ FOREIGN KEY (group_id) REFERENCES groups(group_id) ON DELETE CASCADE;
+--
+-- Re-use old columns in the groups table
+--
+ALTER TABLE groups RENAME COLUMN new_task_address TO new_doc_address;
+ALTER TABLE groups RENAME COLUMN send_all_tasks TO send_all_docs;
+BEGIN;
+UPDATE groups SET new_doc_address='',send_all_docs='0';
+COMMIT;
+
+--
+-- Create a convenience view for selecting from docman
+--
+CREATE VIEW docdata_vw AS
+SELECT users.user_name,users.realname,users.email,doc_data.*,
+ doc_states.name AS state_name,doc_groups.groupname AS group_name
+FROM doc_data
+NATURAL JOIN doc_states
+NATURAL JOIN doc_groups
+JOIN users ON (users.user_id=doc_data.created_by);
More information about the evolvis-commits
mailing list