Example #1
0
 function writeLogChange($old_stauts_id, $item)
 {
     $url = JURI::root();
     $path = JPATH_COMPONENT_SITE . DS . "asset" . DS . "emails" . DS . "change";
     $filename = $path . DS . 'emails_' . $item->id . "_" . time() . '.ini';
     if (!file_exists($filename)) {
         $users = $this->getLog($item->id);
         if ($users) {
             if (intval($item->voice_type_status_id) != intval($old_stauts_id)) {
                 $helper = new JAVoiceHelpers();
                 $mail = $helper->getEmailTemplate("Javnotify_to_user_item_change_status");
                 if (!$mail) {
                     return FALSE;
                 }
                 $header = $helper->getEmailTemplate("mailheader");
                 $footer = $helper->getEmailTemplate("mailfooter");
                 $mailcontent = $header->emailcontent . "\n" . $mail->emailcontent . "\n\n" . $footer->emailcontent;
                 $filters = $helper->getFilterConfig();
                 $model_item = JAVBModel::getInstance('items', 'javoiceModel');
                 $model_item->parseItem($item);
                 $filters["ITEM_TITLE"] = $item->title;
                 $link = $_SERVER['HTTP_HOST'] . str_replace($_SERVER['HTTP_HOST'], '', JRoute::_("index.php?option=com_javoice&view=items&layout=item&cid={$item->id}&type={$item->voice_types_id}&forums={$item->forums_id}"));
                 $filters['ITEM_TITLE_WITH_LINK'] = "<a href=\"{$link}\">" . $item->title . "</a>";
                 $filters["ITEM_FORUM"] = $item->ftitle;
                 $filters["ITEM_VOICE_TYPE"] = $item->ttitle;
                 $filters["ITEM_DESCRIPTON"] = $item->content;
                 $filters["ITEM_CREATE_DATE"] = date('d/M/Y', $item->create_date);
                 $user = JFactory::getUser($item->user_id);
                 $filters["ITEM_CREATE_BY"] = $user->username;
                 $filters["ITEM_NUM_OF_VOTERS"] = $item->number_vote_up + $item->number_vote_down;
                 $filters["ITEM_NUM_OF_VOTERS_DOWN"] = $item->number_vote_down . ", ";
                 $filters["ITEM_TOTAL_VOTE_DOWN"] = $item->total_vote_down;
                 $filters["ITEM_NUM_OF_VOTERS_UP"] = $item->number_vote_up . ", ";
                 $filters["ITEM_TOTAL_VOTE_UP"] = $item->total_vote_up;
                 $filters["ITEM_NEW_STATUS_WITH_COLOR"] = "<span style='background:{$item->class_css}'>" . $item->stitle . "</span>";
                 $filters["ITEM_NEW_STATUS"] = $item->stitle;
                 $old_status = $this->getItem($old_stauts_id);
                 if ($old_status->title == '') {
                     $old_status->class_css = '';
                     $old_status->title = JText::_('HAVING_NO_STATUS');
                 }
                 $filters["ITEM_OLD_STATUS"] = "<span style='background:{$old_status->class_css}'>" . $old_status->title . "</span>";
                 $subject = $mail->subject ? $mail->subject : '';
                 if (is_array($filters)) {
                     foreach ($filters as $key => $value) {
                         $subject = str_replace("{" . $key . "}", $value, $subject);
                         $mailcontent = str_replace("{" . $key . "}", $value, $mailcontent);
                     }
                 }
                 $details = '';
                 $mailcontent = str_replace("\n", "###", $mailcontent);
                 $details .= "subject=" . $subject;
                 $details .= "\nmailcontent={$mailcontent}";
                 $user = implode(",", $users);
                 $details .= "\nuser_id={$user}";
                 $details .= "\nold_status_id=" . $old_stauts_id;
                 $model_sendmail = JAVBModel::getInstance('sendmail', 'javoiceModel');
                 $model_sendmail->writeLogFileChange($details, $filename);
             }
         }
     }
 }
Example #2
0
/**
 * Enter description here...
 * default :run weekly
 * @param unknown_type $nextrun: time next run
 * @param unknown_type $id : tempdata
 * @param unknown_type $name: tempdata
 * @param unknown_type $timerun:time run
 * @return unknown
 */
function writeFileCirculatory($nextrun = 604800, $id = 2, $name = 'weekly', $timerun = 0)
{
    global $javconfig;
    $url = JURI::root();
    $temp = getTempData(" AND name='{$name}' ");
    if ($temp) {
        $time = time();
        if ($time > intval($temp->value) + intval($nextrun)) {
            //write file to send mail weekly
            $path = JPATH_COMPONENT_SITE . DS . "asset" . DS . "emails" . DS . "change";
            $filename = $path . DS . "emails_{$name}" . "_" . time() . '.ini';
            //$model_items = & JModel::getInstance ( 'items', 'javoiceModel' );
            $where = " AND i.create_date BETWEEN {$temp->value} AND {$timerun} AND  i.published=1";
            $items = getItems($where, ' i.create_date DESC ');
            $model_voice_types =& JModel::getInstance('voicetypes', 'javoiceModel');
            $where = " AND t.published = 1 ";
            $voice_types = $model_voice_types->getItems($where, " t.title ", 0, 1000);
            $users = getListUser("%{$name}=1%");
            if (!$voice_types || !$items || !$users) {
                updateNextRun($id, $name, $timerun, $temp);
                return FALSE;
            }
            $items = parseVoiceTypes($voice_types, $items);
            $helper = new JAVoiceHelpers();
            $header = $helper->getEmailTemplate("mailheader");
            $footer = $helper->getEmailTemplate("mailfooter");
            $email = "Javnotify_to_user_new_voice_{$name}";
            $mail = $helper->getEmailTemplate($email);
            $mailcontent = $header->content . "\n" . $mail->content . "\n\n" . $footer->content;
            $filters = $helper->getFilterConfig();
            $details = "";
            $details .= '<UL>';
            foreach ($voice_types as $voice_type) {
                if ($items[$voice_type->id]->list) {
                    $details .= "<LI>";
                    $details .= "<STRONG>" . $voice_type->title . "</STRONG>";
                    $details .= "<OL>";
                    foreach ($items[$voice_type->id]->list as $item) {
                        $details .= "<LI>";
                        $link = $url;
                        $link .= "index.php?option=com_javoice&view=items&layout=item&cid={$item->id}&type={$item->voice_types_id}&forums={$item->forums_id}";
                        $details .= "<a href=\"{$link}\">" . $item->title . "</a>";
                        $integrate = $javconfig['integrate'] ? $javconfig['integrate']->get('run_system', '') : '';
                        $details .= "<span style='color:#7F7F7F'>(";
                        $details .= JText::_("CREATE_DATE") . ": " . date('d/M/Y', $item->create_date);
                        $params = class_exists('JRegistry') ? new JRegistry($item->data) : new JParameter($item->data);
                        $system_total = $integrate . "_total";
                        if ($params->get($system_total)) {
                            $details .= ", " . JText::_("TOTAL_COMMENTS") . ": ";
                            $details .= $params->get($system_total);
                        }
                        $details .= ")</span>";
                    }
                    $details .= "</OL>";
                }
            }
            $details .= "</UL>";
            $filters['{ITEM_DETAILS}'] = $details;
            if (is_array($filters)) {
                foreach ($filters as $key => $value) {
                    $subject = str_replace($key, $value, $mail->subject);
                    $mailcontent = str_replace($key, $value, $mailcontent);
                }
            }
            $mailcontent = str_replace("\n", "###", $mailcontent);
            $content[] = "mailcontent=" . $mailcontent;
            $content[] = "subject=" . $subject;
            $user = implode(",", $users);
            $content[] = "user_id={$user}";
            $contents = implode("\n", $content);
            $model_sendmail = JModel::getInstance('sendmail', 'javoiceModel');
            $model_sendmail->writeLogFileChange($contents, $filename);
            updateNextRun($id, $name, $timerun, $temp);
        }
    }
    return TRUE;
}