/**
  * This function return all folders and subfolder by type, example by INBOX,
  * SENDBOX, etc.
  *
  * @uses $DB
  * @param int $userid User ID
  * @param string $type Folder type (INBOX, SENDBOX, ...). Default EMAIL_INBOX.
  * @return array All folders of these type.
  * @todo Finish documenting this function
  */
 function get_folders($userid, $type = EMAIL_INBOX)
 {
     global $DB;
     email_create_parents_folders($userid);
     // Get root folder.
     $rootfolder = new stdClass();
     $rootfolder = $DB->get_record('block_email_list_folder', array('userid' => $userid, 'isparenttype' => $type));
     $rootfolder->name = get_string($type, 'block_email_list');
     // Get all subfolders
     $subfolders = $this->get_all_subfolders($rootfolder->id);
     return array_merge(array($rootfolder), $subfolders);
 }
/**
 * This function return root folders parent with it.
 *
 * @param int $userid User ID
 * @param boolean $draft Add draft folder
 * @param boolean $trash Add trash folder
 * @param boolean $sendbox Add sendbox folder
 * @param boolean $inbox Add inbox folder
 * @return array Contain all parents folders
 * @todo Finish documenting this function
 **/
function email_get_root_folders($userid, $draft = true, $trash = true, $sendbox = true, $inbox = true)
{
    email_create_parents_folders($userid);
    $folders = array();
    // Include inbox folder
    if ($inbox) {
        $folders[] = email_get_root_folder($userid, EMAIL_INBOX);
    }
    // Include return draft folder
    if ($draft) {
        $folders[] = email_get_root_folder($userid, EMAIL_DRAFT);
    }
    // Include sendbox folder
    if ($sendbox) {
        $folders[] = email_get_root_folder($userid, EMAIL_SENDBOX);
    }
    if ($trash) {
        $folders[] = email_get_root_folder($userid, EMAIL_TRASH);
    }
    return $folders;
}
Exemple #3
0
 /**
  * This functions add mail in user draft folder.
  * Add new mail in table.
  * Add all references in table send.
  *
  * @access public
  * @version 1.0
  * @param int $mailid Old mail ID
  * @return boolean Success/Fail
  * @todo Finish documenting this function
  **/
 function save($mailid = NULL)
 {
     $this->timecreated = time();
     if (!$mailid) {
         $this->insert_mail_record();
         $writer = $this->userid;
         // Prepare send mail
         $send = new stdClass();
         $send->userid = $this->userid;
         $send->course = $this->course;
         $send->mailid = $this->id;
         $send->readed = 0;
         $send->sended = 0;
         // Important
         $send->answered = 0;
         if (!empty($this->to)) {
             // Insert mail into send table, for all senders users.
             foreach ($this->to as $userid) {
                 // In this moment, create if no exist this root folders
                 email_create_parents_folders($userid);
                 $send->userid = $userid;
                 $send->type = 'to';
                 if (!insert_record('block_email_list_send', $send)) {
                     print_error('failinsertsendrecord', 'block_email_list');
                     return false;
                 }
             }
         }
         if (!empty($this->cc)) {
             // Insert mail into send table, for all senders users.
             foreach ($this->cc as $userid) {
                 // In this moment, create if no exist this root folders
                 email_create_parents_folders($userid);
                 $send->userid = $userid;
                 $send->type = 'cc';
                 if (!insert_record('block_email_list_send', $send)) {
                     print_error('failinsertsendrecord', 'block_email_list');
                     return false;
                 }
             }
         }
         if (!empty($this->bcc)) {
             // Insert mail into send table, for all senders users.
             foreach ($this->bcc as $userid) {
                 // In this moment, create if no exist this root folders
                 email_create_parents_folders($userid);
                 $send->userid = $userid;
                 $send->type = 'bcc';
                 if (!insert_record('block_email_list_send', $send)) {
                     print_error('failinsertsendrecord', 'block_email_list');
                     return false;
                 }
             }
         }
         if (!$this->reference_mail_folder($this->userid, EMAIL_DRAFT)) {
             print_error('failinsertrecord', 'block_email_list');
         }
     } else {
         $this->oldmailid = $mailid;
         $this->update_mail_record();
         // Drop all records, and insert all again.
         if (delete_records('block_email_list_send', 'mailid', $mailid)) {
             // Prepare send mail
             $send = new stdClass();
             $send->userid = $this->userid;
             $send->course = $this->course;
             $send->mailid = $mailid;
             $send->readed = 0;
             $send->sended = 0;
             // Important
             $send->answered = 0;
             // Now, I must verify the users who sended mail, in case they have changed.
             if (!empty($this->to)) {
                 // Insert mail into send table, for all senders users.
                 foreach ($this->to as $userid) {
                     $send->userid = $userid;
                     $send->type = 'to';
                     if (!insert_record('block_email_list_send', $send)) {
                         print_error('failinsertsendrecord', 'block_email_list');
                         return false;
                     }
                 }
             }
             if (!empty($this->cc)) {
                 // Insert mail into send table, for all senders users.
                 foreach ($this->cc as $userid) {
                     $send->userid = $userid;
                     $send->type = 'cc';
                     if (!insert_record('block_email_list_send', $send)) {
                         print_error('failinsertsendrecord', 'block_email_list');
                         return false;
                     }
                 }
             }
             if (!empty($this->bcc)) {
                 // Insert mail into send table, for all senders users.
                 foreach ($this->bcc as $userid) {
                     $send->userid = $userid;
                     $send->type = 'bcc';
                     if (!insert_record('block_email_list_send', $send)) {
                         print_error('failinsertsendrecord', 'block_email_list');
                         return false;
                     }
                 }
             }
         }
     }
     // Add attachments
     if ($this->attachments or $this->oldattachments) {
         if (!$this->add_attachments()) {
             notify('Fail uploading attachments');
         }
     }
     add_to_log($this->course, 'email_list', "add mail in draft", 'sendmail.php', "{$this->subject}", 0, $this->userid);
     return $this->id;
 }