Exemplo n.º 1
0
/**
 * Generate the compose data package consumed by the full and quick compose screens.
 *
 * @param Array $data
 * @param Bool $forFullCompose If full compose is set to TRUE, then continue execution and include the full Emails UI.  Otherwise
 *             the data generated is returned.
 * @param SugarBean $bean Optional - parent object with data
 */
function generateComposeDataPackage($data, $forFullCompose = TRUE, $bean = null)
{
    // we will need the following:
    if (isset($data['parent_type']) && !empty($data['parent_type']) && isset($data['parent_id']) && !empty($data['parent_id']) && !isset($data['ListView']) && !isset($data['replyForward'])) {
        if (empty($bean)) {
            global $beanList;
            global $beanFiles;
            global $mod_strings;
            $parentName = '';
            $class = $beanList[$data['parent_type']];
            require_once $beanFiles[$class];
            $bean = new $class();
            $bean->retrieve($data['parent_id']);
        }
        if (isset($bean->full_name)) {
            $parentName = $bean->full_name;
        } elseif (isset($bean->name)) {
            $parentName = $bean->name;
        } else {
            $parentName = '';
        }
        $parentName = from_html($parentName);
        $namePlusEmail = '';
        if (isset($data['to_email_addrs'])) {
            $namePlusEmail = $data['to_email_addrs'];
            $namePlusEmail = from_html(str_replace(" ", " ", $namePlusEmail));
        } else {
            if (isset($bean->full_name)) {
                $namePlusEmail = from_html($bean->full_name) . " <" . from_html($bean->emailAddress->getPrimaryAddress($bean)) . ">";
            } else {
                if (isset($bean->emailAddress)) {
                    $namePlusEmail = "<" . from_html($bean->emailAddress->getPrimaryAddress($bean)) . ">";
                }
            }
        }
        $subject = "";
        $body = "";
        $email_id = "";
        $attachments = array();
        if ($bean->module_dir == 'Cases') {
            $subject = str_replace('%1', $bean->case_number, $bean->getEmailSubjectMacro() . " " . from_html($bean->name));
            //bug 41928
            $bean->load_relationship("contacts");
            $contact_ids = $bean->contacts->get();
            $contact = new Contact();
            foreach ($contact_ids as $cid) {
                $contact->retrieve($cid);
                $namePlusEmail .= empty($namePlusEmail) ? "" : ", ";
                $namePlusEmail .= from_html($contact->full_name) . " <" . from_html($contact->emailAddress->getPrimaryAddress($contact)) . ">";
            }
        }
        if ($bean->module_dir == 'KBDocuments') {
            require_once "modules/Emails/EmailUI.php";
            $subject = $bean->kbdocument_name;
            $article_body = str_replace('/cache/images/', $GLOBALS['sugar_config']['site_url'] . '/cache/images/', KBDocument::get_kbdoc_body_without_incrementing_count($bean->id));
            $body = from_html($article_body);
            $attachments = KBDocument::get_kbdoc_attachments_for_newemail($bean->id);
            $attachments = $attachments['attachments'];
        }
        // if
        if ($bean->module_dir == 'Quotes' && isset($data['recordId'])) {
            $quotesData = getQuotesRelatedData($bean, $data);
            global $current_language;
            $namePlusEmail = $quotesData['toAddress'];
            $subject = $quotesData['subject'];
            $body = $quotesData['body'];
            $attachments = $quotesData['attachments'];
            $email_id = $quotesData['email_id'];
        }
        // if
        $ret = array('to_email_addrs' => $namePlusEmail, 'parent_type' => $data['parent_type'], 'parent_id' => $data['parent_id'], 'parent_name' => $parentName, 'subject' => $subject, 'body' => $body, 'attachments' => $attachments, 'email_id' => $email_id);
    } else {
        if (isset($_REQUEST['ListView'])) {
            $email = new Email();
            $namePlusEmail = $email->getNamePlusEmailAddressesForCompose($_REQUEST['action_module'], explode(",", $_REQUEST['uid']));
            $ret = array('to_email_addrs' => $namePlusEmail);
        } else {
            if (isset($data['replyForward'])) {
                require_once "modules/Emails/EmailUI.php";
                $ret = array();
                $ie = new InboundEmail();
                $ie->email = new Email();
                $ie->email->email2init();
                $replyType = $data['reply'];
                $email_id = $data['record'];
                $ie->email->retrieve($email_id);
                $emailType = "";
                if ($ie->email->type == 'draft') {
                    $emailType = $ie->email->type;
                }
                $ie->email->from_addr = $ie->email->from_addr_name;
                $ie->email->to_addrs = to_html($ie->email->to_addrs_names);
                $ie->email->cc_addrs = to_html($ie->email->cc_addrs_names);
                $ie->email->bcc_addrs = $ie->email->bcc_addrs_names;
                $ie->email->from_name = $ie->email->from_addr;
                $preBodyHTML = "&nbsp;<div><hr></div>";
                if ($ie->email->type != 'draft') {
                    $email = $ie->email->et->handleReplyType($ie->email, $replyType);
                } else {
                    $email = $ie->email;
                    $preBodyHTML = "";
                }
                // else
                if ($ie->email->type != 'draft') {
                    $emailHeader = $email->description;
                }
                $ret = $ie->email->et->displayComposeEmail($email);
                if ($ie->email->type != 'draft') {
                    $ret['description'] = $emailHeader;
                }
                if ($replyType == 'forward' || $emailType == 'draft') {
                    $ret = $ie->email->et->getDraftAttachments($ret);
                }
                $return = $ie->email->et->getFromAllAccountsArray($ie, $ret);
                if ($replyType == "forward") {
                    $return['to'] = '';
                } else {
                    if ($email->type != 'draft') {
                        $return['to'] = from_html($ie->email->from_addr);
                    }
                }
                // else
                $ret = array('to_email_addrs' => $return['to'], 'parent_type' => $return['parent_type'], 'parent_id' => $return['parent_id'], 'parent_name' => $return['parent_name'], 'subject' => $return['name'], 'body' => $preBodyHTML . $return['description'], 'attachments' => isset($return['attachments']) ? $return['attachments'] : array(), 'email_id' => $email_id, 'fromAccounts' => $return['fromAccounts']);
                // If it's a 'Reply All' action, append the CC addresses
                if ($data['reply'] == 'replyAll') {
                    $ret['cc_addrs'] = from_html($ie->email->to_addrs);
                }
            } else {
                $ret = array('to_email_addrs' => '');
            }
        }
    }
    if ($forFullCompose) {
        initFullCompose($ret);
    } else {
        return $ret;
    }
}
Exemplo n.º 2
0
 * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
 * All Rights Reserved.
 * Contributor(s): ______________________________________..
 ********************************************************************************/
global $mod_strings;
global $sugar_config;
if (!isset($_REQUEST['record'])) {
    sugar_die($mod_strings['ERR_DELETE_RECORD']);
}
$focus = BeanFactory::getBean('KBDocuments', $_REQUEST['record']);
if (!$focus->ACLAccess('Delete')) {
    ACLController::displayNoAccess(true);
    sugar_cleanup(true);
}
//Retrieve all related kbdocument revisions.
$kbdocrevs = KBDocument::get_kbdocument_revisions($_REQUEST['record']);
//Loop through kbdocument revisions and delete one by one.
if (!empty($kbdocrevs) && is_array($kbdocrevs)) {
    foreach ($kbdocrevs as $key => $thiskbid) {
        $thiskbversion = BeanFactory::getBean('KBDocumentRevisions', $thiskbid);
        //Check for related documentrevision and delete.
        if ($thiskbversion->document_revision_id != null) {
            $docrev_id = $thiskbversion->document_revision_id;
            $thisdocrev = BeanFactory::getBean('DocumentRevisions', $docrev_id);
            UploadFile::unlink_file($docrev_id, $thisdocrev->filename);
            UploadFile::unlink_file($docrev_id);
            //mark version deleted
            $thisdocrev->mark_deleted($thisdocrev->id);
        }
        //Also check for related kbcontent and delete.
        if ($thiskbversion->kbcontent_id != null) {
Exemplo n.º 3
0
}
if ($load_signed) {
    $xtpl->assign("RELATED_DOCUMENT_REVISION_DISABLED", "disabled");
    $xtpl->assign("RELATED_DOCUMENT_BUTTON_AVAILABILITY", "hidden");
    $xtpl->assign("LOAD_SIGNED_ID", $_REQUEST['load_signed_id']);
} else {
    $xtpl->assign("RELATED_DOCUMENT_BUTTON_AVAILABILITY", "button");
}
/////////////////////////
require_once 'include/SugarTinyMCE.php';
$tiny = new SugarTinyMCE();
$tiny->defaultConfig['cleanup_on_startup'] = true;
$ed = $tiny->getInstance('body_html');
$xtpl->assign("tiny", $ed);
$edValue = '';
$kbDocBody = from_html(KBDocument::get_kbdoc_body_without_incrementing_count($kbId));
if (!empty($kbDocBody)) {
    $edValue = $kbDocBody;
} else {
    if (!empty($from_case)) {
        //set the kb fields from case i.e. kb name
        if (!empty($from_case->case_number)) {
            $edValue = '<p>Case Number: ' . $from_case->case_number . '</p>';
        }
        if (!empty($from_case->name)) {
            $edValue .= '<p>Subject: ' . $from_case->name . '</p>';
        }
        if (!empty($from_case->description)) {
            $edValue .= '<p>Description: ' . $from_case->description . '</p>';
        }
        if (!empty($from_case->resolution)) {
Exemplo n.º 4
0
    $contract->save();
}
echo '.';
///
/// SEED DATA FOR KNOWLEDGE BASE
///
$kbtags_hash = array();
foreach ($sugar_demodata['kbdocument_seed_data_kbtags'] as $v) {
    $kbtag = new KBTag();
    $kbtag->tag_name = $v;
    $id = $kbtag->save();
    $kbtags_hash[$id] = $v;
}
echo '.';
foreach ($sugar_demodata['kbdocument_seed_data'] as $v) {
    $kbdoc = new KBDocument();
    $kbdoc->kbdocument_name = $v['name'];
    $kbdoc->status_id = 'Published';
    $kbdoc->team_id = 1;
    $kbdoc->assigned_user_id = 'seed_will_id';
    $kbdoc->active_date = $v['start_date'];
    $kbdoc->exp_date = $v['exp_date'];
    $kbdoc->is_external_article = 1;
    $kbdoc->save();
    $kbdocRevision = new KBDocumentRevision();
    $kbdocRevision->change_log = translate('DEF_CREATE_LOG', 'KBDocuments');
    $kbdocRevision->revision = '1';
    $kbdocRevision->kbdocument_id = $kbdoc->id;
    $kbdocRevision->latest = true;
    $kbdocRevision->save();
    $docRevision = new DocumentRevision();
Exemplo n.º 5
0
        }
    }
    $subject = "";
    $body = "";
    $email_id = "";
    $attachments = array();
    if ($bean->module_dir == 'Cases') {
        $subject = $mod_strings['LBL_RE'] . " " . str_replace('%1', $bean->case_number, $bean->getEmailSubjectMacro() . " " . $bean->name);
    }
    if ($bean->module_dir == 'KBDocuments') {
        require_once 'modules/KBDocuments/KBDocument.php';
        require_once "modules/Emails/EmailUI.php";
        $subject = $bean->kbdocument_name;
        $article_body = str_replace('/cache/images/', $sugar_config['site_url'] . '/cache/images/', KBDocument::get_kbdoc_body_without_incrementing_count($bean->id));
        $body = from_html($article_body);
        $attachments = KBDocument::get_kbdoc_attachments_for_newemail($bean->id);
        $attachments = $attachments['attachments'];
    }
    // if
    if ($bean->module_dir == 'Quotes' && isset($_REQUEST['recordId'])) {
        $quotesData = getQuotesRelatedData($bean);
        global $current_language;
        $namePlusEmail = $quotesData['toAddress'];
        $subject = $quotesData['subject'];
        $body = $quotesData['body'];
        $attachments = $quotesData['attachments'];
        $email_id = $quotesData['email_id'];
    }
    // if
    $ret = array('to_email_addrs' => $namePlusEmail, 'parent_type' => $_REQUEST['parent_type'], 'parent_id' => $_REQUEST['parent_id'], 'parent_name' => $parentName, 'subject' => $subject, 'body' => $body, 'attachments' => $attachments, 'email_id' => $email_id);
} else {
Exemplo n.º 6
0
$xtpl->assign("GRIDLINE", $gridline);
$xtpl->assign("PRINT_URL", "index.php?" . $GLOBALS['request_string']);
$xtpl->assign("ID", $focus->id);
$xtpl->assign("DOCUMENT_NAME", $focus->kbdocument_name);
//$xtpl->assign("REVISION", $focus->latest_revision);
$xtpl->assign("REVISION", $focus->kbdocument_revision_number);
if ($focus->parent_id != null) {
    $xtpl->assign("CASE_NAME", $focus->case_name);
    $xtpl->assign("CASE_ID", $focus->parent_id);
}
global $locale;
$xtpl->assign("KBDOC_TAGS", KBDocument::get_kbdoc_tags_heirarchy($focus->id, "Detail"));
//get the document body
$article_body = KBDocument::get_kbdoc_body_without_incrementing_count($focus->id);
$xtpl->assign("KBDOC_BODY", from_html($article_body));
$xtpl->assign("KBDOC_ATTS", KBDocument::get_kbdoc_attachments($focus->id, "Detail"));
if (isset($focus->status_id) && isset($app_list_strings['kbdocument_status_dom']) && isset($app_list_strings['kbdocument_status_dom'][$focus->status_id])) {
    $xtpl->assign("STATUS", $app_list_strings['kbdocument_status_dom'][$focus->status_id]);
}
$xtpl->assign("FILE_URL", $focus->file_url);
$xtpl->assign("ACTIVE_DATE", $focus->active_date);
$xtpl->assign("EXP_DATE", $focus->exp_date);
$xtpl->assign("FILE_NAME", $focus->filename);
$xtpl->assign("FILE_URL_NOIMAGE", $focus->file_url_noimage);
$xtpl->assign("LAST_REV_CREATOR", $focus->last_rev_created_name);
$buttons = array(<<<EOD
            <input title="{$app_strings['LBL_EDIT_BUTTON_TITLE']}" id="edit_button" accessKey="{$app_strings['LBL_EDIT_BUTTON_KEY']}" class="button primary" onclick="this.form.return_module.value='KBDocuments'; this.form.return_action.value='DetailView'; this.form.return_id.value='{$focus->id}'; this.form.action.value='EditView'" type="submit" name="Edit" value="{$app_strings['LBL_EDIT_BUTTON_LABEL']}">
EOD
, <<<EOD
            <input title="{$app_strings['LBL_DUPLICATE_BUTTON_TITLE']}" id="duplicate_button" accessKey="{$app_strings['LBL_DUPLICATE_BUTTON_KEY']}" class="button" onclick="this.form.return_module.value='KBDocuments'; this.form.return_action.value='index'; this.form.isDuplicate.value=true; this.form.action.value='EditView'" type="submit" name="Duplicate" value="{$app_strings['LBL_DUPLICATE_BUTTON_LABEL']}">
EOD
Exemplo n.º 7
0
 function fill_in_additional_detail_fields()
 {
     global $theme;
     global $current_language;
     global $timedate;
     parent::fill_in_additional_detail_fields();
     $mod_strings = return_module_language($current_language, 'KBDocuments');
     $query = "SELECT filename,revision,file_ext FROM kbdocument_revisions WHERE id='{$this->kbdocument_revision_id}'";
     $result = $this->db->query($query);
     $row = $this->db->fetchByAssoc($result);
     //popuplate filename
     $this->filename = $row['filename'];
     $this->latest_revision = $row['revision'];
     //populate the file url.
     //image is selected based on the extension name <ext>_icon_inline, extension is stored in document_revisions.
     //if file is not found then default image file will be used.
     global $img_name;
     global $img_name_bare;
     if (!empty($row['file_ext'])) {
         $img_name = SugarThemeRegistry::current()->getImageURL(strtolower($row['file_ext']) . "_image_inline.gif");
         $img_name_bare = strtolower($row['file_ext']) . "_image_inline";
     }
     //set default file name.
     if (!empty($img_name) && file_exists($img_name)) {
         $img_name = $img_name_bare;
     } else {
         $img_name = "def_image_inline";
         //todo change the default image.
     }
     $this->file_url = "<a href='index.php?entryPoint=download&id={$this->document_revision_id}&type=Documents' target='_blank'>" . SugarThemeRegistry::current()->getImage($img_name, 'border="0"', null, null, '.gif', $mod_strings['LBL_LIST_VIEW_DOCUMENT']) . "</a>";
     $this->file_url_noimage = "index.php?entryPoint=download&type=Documents&id={$this->document_revision_id}";
     //get last_rev_by user name.
     $query = "SELECT first_name,last_name, document_revisions.date_entered as rev_date FROM users, document_revisions WHERE users.id = document_revisions.created_by and document_revisions.id = '{$this->document_revision_id}'";
     $result = $this->db->query($query, true, "Eror fetching user name: ");
     $row = $this->db->fetchByAssoc($result);
     if (!empty($row)) {
         $this->last_rev_created_name = $row['first_name'] . ' ' . $row['last_name'];
         $this->last_rev_create_date = $timedate->to_display_date_time($row['rev_date']);
     }
     $this->name = $this->kbdocument_name;
     $this->body = html_entity_decode(KBDocument::get_kbdoc_body_without_incrementing_count($this->id), ENT_COMPAT | ENT_QUOTES, 'UTF-8');
 }
//PARAMN_ are node level parameters.
$json = getJSONobj();
$selectedArticles = $json->decode(html_entity_decode($_REQUEST['selectedArticles']));
if (isset($selectedArticles['jsonObject']) && $selectedArticles['jsonObject'] != null) {
    $selectedArticles = $selectedArticles['jsonObject'];
}
foreach ($selectedArticles as $articleId) {
    if (!empty($articleId)) {
        //retrieve article
        $kbarticle = BeanFactory::getBean('KBDocuments', $articleId);
        $deleted = 1;
        //also retrieve children and check if there is any article linked
        $kbarticle->deleted = 1;
        $kbarticle->save();
        //also delete related
        $kbdocrevs = KBDocument::get_kbdocument_revisions($articleId);
        if (!empty($kbdocrevs) && is_array($kbdocrevs)) {
            foreach ($kbdocrevs as $key => $thiskbid) {
                $thiskbversion = BeanFactory::getBean('KBDocumentRevisions', $thiskbid);
                $docrev_ids = KBDocumentRevision::get_docrevs($thiskbid);
                foreach ($docrev_ids as $key => $thisdocrevid) {
                    $thisdocrev = BeanFactory::getBean('DocumentRevisions', $thisdocrevid);
                    UploadFile::unlink_file($thisdocrevid, $thisdocrev->filename);
                    //mark version deleted
                    $thisdocrev->mark_deleted($thisdocrev->id);
                    //also retrieve the content
                    if ($thisdocrev->file_ext == null && $thisdocrev->file_mime_type == null) {
                        //this is content retrieve and mark it delete
                    }
                }
                //mark kbdoc revision deleted