home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 April / CMCD0404.ISO / Software / Freeware / Programare / groupoffice-com-2.01 / classes / notes.class.inc < prev    next >
Text File  |  2004-03-08  |  6KB  |  224 lines

  1. <?php
  2. /*
  3. Copyright Intermesh 2003
  4. Author: Merijn Schering <mschering@intermesh.nl>
  5. Version: 1.0 Release date: 2 Januari 2004
  6.  
  7. Part of the Group-Office Professional license
  8. */
  9.  
  10. define('SHOW_ALL', 1);
  11. define('SHOW_OWN', 2);
  12. define('SHOW_RESPONSIBLE', 3);
  13.  
  14. class notes extends db
  15. {
  16.     function notes()
  17.     {
  18.         $this->db();
  19.     }
  20.  
  21.     function add_note($user_id, $contact_id, $project_id, $file_path, $catagory_id, $res_user_id, $due_date, $name, $content, $acl_read, $acl_write)
  22.     {
  23.         $note_id = $this->nextid("no_notes");
  24.  
  25.         if ($note_id > 0)
  26.         {
  27.             $sql = "INSERT INTO no_notes (id, user_id, contact_id, project_id, file_path, catagory_id, res_user_id, due_date, name, content, ctime, mtime, acl_read, acl_write) ".
  28.                     "VALUES ('$note_id', '$user_id', '$contact_id', '$project_id', '$file_path', '$catagory_id', '$res_user_id', '$due_date', '".smart_addslashes($name)."', '".smart_addslashes($content)."', '".get_gmt_time()."', '".get_gmt_time()."', '$acl_read', '$acl_write')";
  29.             if($this->query($sql))
  30.             {
  31.                 return $note_id;
  32.             }
  33.         }
  34.         return false;
  35.     }
  36.  
  37.     function get_note($note_id)
  38.     {
  39.         $sql = "SELECT * FROM no_notes WHERE id='$note_id'";
  40.         $this->query($sql);
  41.         if ($this->next_record())
  42.         {
  43.             return $this->Record;
  44.         }
  45.         return false;
  46.     }
  47.  
  48.     function delete_note($note_id)
  49.     {
  50.         $sql = "DELETE FROM no_notes WHERE id='$note_id'";
  51.         return $this->query($sql);
  52.     }
  53.  
  54.  
  55.     function update_note($note_id, $name, $catagory_id, $res_user_id, $due_date, $content)
  56.     {
  57.         $sql = "UPDATE no_notes SET res_user_id='$res_user_id', due_date='$due_date', catagory_id='$catagory_id', name='".smart_addslashes($name)."', content='".addslashes($content)."', catagory_id='$catagory_id', mtime='".get_gmt_time()."' WHERE id='$note_id'";
  58.  
  59.         return $this->query($sql);
  60.     }
  61.  
  62.     function get_note_by_name($name)
  63.     {
  64.         $sql = "SELECT * FROM no_notes WHERE name='".smart_addslashes($name)."'";
  65.         $this->query($sql);
  66.         if ($this->next_record())
  67.         {
  68.             return $this->Record;
  69.         }
  70.         return false;
  71.     }
  72.  
  73.     function get_notes($user_id=0, $project_id=0, $contact_id=0, $file_path='', $show, $sort='name', $direction='ASC', $start=0, $offset=0)
  74.     {
  75.         $sql = "SELECT DISTINCT no_notes.*, no_catagories.name AS catagory_name FROM no_notes ".
  76.                 "INNER JOIN acl ON (no_notes.acl_read = acl.acl_id OR no_notes.acl_write = acl.acl_id) ".
  77.                 "LEFT JOIN users_groups ON (acl.group_id = users_groups.group_id) ".
  78.                 "LEFT JOIN no_catagories ON (no_notes.catagory_id=no_catagories.id)".
  79.                 " WHERE ((users_groups.user_id = ".$user_id." AND acl.user_id = 0 ) OR (".
  80.                 "acl.group_id = 0 AND acl.user_id = ".$user_id."))";
  81.  
  82.  
  83.         if ($contact_id != 0)
  84.         {
  85.             $sql .= " AND no_notes.contact_id='$contact_id'";
  86.         }
  87.  
  88.         if ($project_id != 0)
  89.         {
  90.             $sql .= " AND no_notes.project_id='$project_id'";
  91.         }
  92.  
  93.         if ($file_path != '')
  94.         {
  95.             $sql .= " AND no_notes.file_path='$file_path'";
  96.         }
  97.  
  98.         switch ($show)
  99.         {
  100.             case SHOW_OWN:
  101.                 $sql .= " AND no_notes.user_id='$user_id'";
  102.             break;
  103.  
  104.             case SHOW_RESPONSIBLE:
  105.  
  106.                 $sql .= " AND no_notes.res_user_id='$user_id'";
  107.             break;
  108.         }
  109.  
  110.         $sql .= " ORDER BY $sort $direction";
  111.  
  112.         if ($offset > 0)
  113.         {
  114.             $sql .= " LIMIT $start, $offset";
  115.  
  116.             $sql2 = "SELECT DISTINCT id FROM no_notes ".
  117.                     "INNER JOIN acl ON (no_notes.acl_read = acl.acl_id OR no_notes.acl_write = acl.acl_id) ".
  118.                     "LEFT JOIN users_groups ON (acl.group_id = users_groups.group_id) WHERE ((".
  119.                     "users_groups.user_id = ".$user_id." AND acl.user_id = 0 ) OR (".
  120.                     "acl.group_id = 0 AND acl.user_id = ".$user_id."))";
  121.  
  122.             if ($contact_id != 0)
  123.             {
  124.                 $sql2 .= " AND no_notes.contact_id='$contact_id'";
  125.             }
  126.  
  127.             if ($project_id != 0)
  128.             {
  129.                 $sql2 .= " AND no_notes.project_id='$project_id'";
  130.             }
  131.  
  132.             if ($file_path != '')
  133.             {
  134.                 $sql2 .= " AND no_notes.file_path='$file_path'";
  135.             }
  136.  
  137.             switch ($show)
  138.             {
  139.                 case SHOW_OWN:
  140.                     $sql2 .= " AND no_notes.user_id='$user_id'";
  141.                 break;
  142.  
  143.                 case SHOW_RESPONSIBLE:
  144.  
  145.                     $sql2 .= " AND no_notes.res_user_id='$user_id'";
  146.                 break;
  147.             }
  148.  
  149.             $this->query($sql2);
  150.  
  151.             $count = $this->num_rows();
  152.             if ($count > 0)
  153.             {
  154.                 $this->query($sql);
  155.             }
  156.             return $count;
  157.  
  158.         }else
  159.         {
  160.             $this->query($sql);
  161.             return $this->num_rows();
  162.         }
  163.     }
  164.  
  165.     function add_catagory($name)
  166.     {
  167.         $catagory_id = $this->nextid("no_catagories");
  168.  
  169.         if ($catagory_id > 0)
  170.         {
  171.             $sql = "INSERT INTO no_catagories (id, name) ".
  172.                     "VALUES ('$catagory_id', '".smart_addslashes($name)."')";
  173.             return $this->query($sql);
  174.         }
  175.         return false;
  176.     }
  177.  
  178.     function update_catagory($catagory_id, $name)
  179.     {
  180.         $sql = "UPDATE no_catagories SET  name='".smart_addslashes($name)."' WHERE id='$catagory_id'";
  181.         return $this->query($sql);
  182.     }
  183.  
  184.     function get_catagory_by_name($name)
  185.     {
  186.         $sql = "SELECT * FROM no_catagories WHERE name='".smart_addslashes($name)."'";
  187.         $this->query($sql);
  188.         if ($this->next_record())
  189.         {
  190.             return $this->Record;
  191.         }
  192.         return false;
  193.     }
  194.  
  195.     function get_catagories()
  196.     {
  197.         $sql = "SELECT * FROM no_catagories ORDER BY name ASC";
  198.         $this->query($sql);
  199.         return $this->num_rows();
  200.     }
  201.  
  202.     function delete_catagory($catagory_id)
  203.     {
  204.         $sql = "DELETE FROM no_catagories WHERE id='$catagory_id'";
  205.         return $this->query($sql);
  206.     }
  207.     function get_catagory($catagory_id)
  208.     {
  209.         $sql = "SELECT * FROM no_catagories WHERE id='$catagory_id'";
  210.         $this->query($sql);
  211.         if ($this->next_record())
  212.         {
  213.             return $this->Record;
  214.         }
  215.         return false;
  216.     }
  217.  
  218.     function delete_user($user_id)
  219.     {
  220.         $sql = "DELETE FROM no_notes WHERE user_id='$user_id'";
  221.         $this->query($sql);
  222.     }
  223. }
  224. ?>