コード例 #1
0
 /**
  * Perform the main actions of the page.
  * @global array
  */
 protected function action()
 {
     $i2ce_config = I2CE::getConfig()->I2CE;
     parent::action();
     $fields = array("Name" => false, "Company" => false, "Title" => false, "Industry" => false, "Address" => false, "City" => false, "State" => false, "Postal_Code" => false, "Country" => false, "Telephone" => false, "Fax" => false, "Email" => false, "Comments" => false, "referer" => false);
     $valid = true;
     $err_msg = "";
     if ($this->isPost()) {
         $message = "";
         foreach ($fields as $name => $required) {
             if ($required && !I2CE_Validate::checkString($this->post($name))) {
                 $valid = false;
                 $err_msg .= "<li>{$name} is blank.</li>\n";
             }
             $message .= $name . ": " . $this->post($name) . "\n";
         }
         $message .= "Username : "******"\n";
         $message .= "User Role : " . $this->user->getRole() . "\n";
         if ($valid) {
             $this->template->addFile("feedback_thanks.html");
             $this->template->setDisplayData("return_link", 'home');
             I2CE_Mailer::mail($i2ce_config->feedback->to, array('Subject' => $i2ce_config->feedback->subject, 'From' => $this->post('Email')), $message);
             return;
         }
     }
     $this->template->addFile("feedback_form.html");
     if (array_key_exists('contact_address', $this->args) && $this->args['contact_address']) {
         if (($formNode = $this->template->getElementById('feedback_form')) instanceof DOMElement) {
             $formNode->setAttribute('action', 'mailto:' . $this->args['contact_address'] . '?Subject=iHRIS Feedback');
             $formNode->setAttribute('enctype', 'text/plain');
         }
     }
     if (!$valid && $err_msg != "") {
         $this->template->addText('<div id="error">There were some problems with your information:<ul>' . $err_msg . '</ul></div>');
     }
     if ($this->isPost()) {
         foreach ($fields as $name => $required) {
             if ($name == "Comments") {
                 $this->template->addText('<textarea name="Comments" rows="10" cols="45" id="Comments">' . $this->post($name) . '</textarea>', "textarea", $name);
             } else {
                 $this->template->setAttribute("value", $this->post($name), $name, ".");
             }
         }
     } else {
         $this->template->setAttribute("value", $_SERVER['HTTP_REFERER'], "referer", ".");
         if (!array_key_exists('auto_populate', $this->args) || $this->args['auto_populate']) {
             //defaults to true
             foreach (array('email' => 'Email', 'phone' => 'Phone', 'fax' => 'Fax') as $detail => $data) {
                 if (I2CE_User::hasDetail($detail)) {
                     $this->template->setDisplayDataImmediate($data, $this->user->{$detail});
                 }
             }
             $this->template->setDisplayDataImmediate('Name', $this->user->displayName());
         }
     }
 }
コード例 #2
0
 protected function mailPassword($email, $username, $password)
 {
     $i2ce_config = I2CE::getConfig()->I2CE;
     $msg = "The password for your account in " . $i2ce_config->template->prefix_title . " has been reset.\n\nUsername: "******"\nPassword: "******"\n";
     if (!I2CE_Mailer::mail($email, array('Subject' => "New " . $i2ce_config->template->prefix_title . " Password"), $msg)) {
         I2CE::raiseError("Could not mail reset password to {$username}");
         return false;
     }
     $this->userMessage("Your password has been reset and is being mailed to you now.");
     return true;
 }
コード例 #3
0
 protected static function initMailer()
 {
     $backend = "mail";
     I2CE::getConfig()->setIfIsSet($backend, "/modules/Mailer/mail_server_backend");
     I2CE::getConfig()->setIfIsSet(self::$params, "/modules/Mailer/mail_server_params", true);
     I2CE::getConfig()->setIfIsSet(self::$headers, "/modules/Mailer/mail_message_headers", true);
     if (class_exists('Mail', false)) {
         self::$method = 'pear';
         $allowed_backends = array("mail", "smtp", "sendmail");
     } else {
         I2CE::raiseError("No Mail class : try 'sudo apt-get install pear-mail'");
         self::$method = 'localhost';
         $allowed_backends = array("localhost");
     }
     if (!in_array($backend, $allowed_backends)) {
         I2CE::raiseError("Mailing backend {$backend} is not in list: " . implode(" ", $allowed_backends));
         self::$method = false;
         return false;
     }
     if (self::$method == 'pear') {
         if (array_key_exists('auth', self::$params) && self::$params['auth'] == 1) {
             self::$params['auth'] = true;
         }
         try {
             self::$pear_mailer =& Mail::factory($backend, self::$params);
         } catch (Exception $e) {
             I2CE::raiseError("Could not create pear mailer:\n" . $e->getMessage());
             self::$method = false;
             return false;
         }
     }
 }
コード例 #4
0
 /**
  * Handler for mail triggers
  * @param string $username The username to be notified
  * @param string $trigger The trigger being called
  * @param string $message The message to send
  * @param string $link The optional link to include
  * @param string $link_text The link text for the link
  * @param array $args Any option arguments for this trigger handler
  * @return boolean
  */
 public function triggerEmail($username, $trigger, $message, $link = false, $link_text = '', $args = array())
 {
     $user = I2CE_FormFactory::instance()->createContainer("user|" . $username);
     $user->populate();
     $email = $user->email;
     if (!I2CE_Validate::checkEmail($email)) {
         I2CE::raiseError("Invalid email to {$email} for {$username} while sending trigger: {$trigger}");
         return false;
     }
     $display = $trigger;
     $this->config->setIfIsSet($display, "triggers/{$trigger}/display");
     $subject = '';
     if (array_key_exists('subject', $args)) {
         $subject = $args['subject'];
     } else {
         $this->config->setIfIsSet($subject, "messages/default_email_subject");
         if ($subject = '') {
             $subject = 'Automated email for ' . $display;
         } else {
             $subject .= " {$display}";
         }
     }
     $full_message = $message;
     if ($link) {
         $full_message .= "\n\n";
         if ($link_text) {
             $full_message .= "{$link_text}: ";
         }
         $full_message .= "{$link}\n";
     }
     $full_message = wordwrap($full_message);
     if (!I2CE_Mailer::mail($email, array('Subject' => $subject), $full_message)) {
         I2CE::raiseError("Unable to send message to {$email} for trigger.");
         return false;
     }
     return true;
 }
コード例 #5
0
 protected function sendVerificationEmail()
 {
     $verify_only = false;
     $msg_html = false;
     I2CE::getConfig()->setIfIsSet($verify_only, "/modules/RequestAccount-VerifyEmail/verify_only");
     if ($verify_only) {
         I2CE::getConfig()->setIfIsSet($msg, "/modules/RequestAccount-VerifyEmail/user_messages/email_message_verify_only");
         I2CE::getConfig()->setIfIsSet($msg_html, "/modules/RequestAccount-VerifyEmail/user_messages/email_message_verify_only_html");
     } else {
         I2CE::getConfig()->setIfIsSet($msg, "/modules/RequestAccount-VerifyEmail/user_messages/email_message");
         if (!I2CE::getConfig()->setIfIsSet($msg_html, "/modules/RequestAccount-VerifyEmail/user_messages/email_message_html")) {
             I2CE::raiseError("NO HTML");
         }
     }
     I2CE::getConfig()->setIfIsSet($subject, "/modules/RequestAccount-VerifyEmail/user_messages/email_subject");
     $site_link = I2CE_Page::getAccessedBaseURL() . '/' . $this->pageRoot();
     $link = $site_link . "?verify=" . $this->requested_user->getField('request_number')->getValue();
     $username = $this->requested_user->username;
     $email = $this->requested_user->email;
     $site = 'I2CE';
     I2CE::getConfig()->setIfIsSet($site, "/I2CE/template/prefix_title");
     $msg = sprintf($msg, $username, $link, $site, $site_link);
     if ($msg_html) {
         $msg_html = sprintf($msg_html, $username, $link, $site, $site_link);
     }
     $subject = sprintf($subject, $site);
     if (!$email || !$msg || !$subject) {
         I2CE::raiseError("Invalid message<{$msg}> or subject<{$subject}> or email<{$email}>");
         return false;
     }
     I2CE::raiseError("Want to send email to {$email} with subject {$subject}");
     I2CE::raiseError("Want to send email to user {$username} with message {$msg}");
     I2CE::raiseError("Want to send email to user {$username} with message  html " . $msg_html);
     if (!I2CE_Mailer::mail($email, array('Subject' => $subject), $msg, $msg_html)) {
         I2CE::raiseError("Could not mail verification message to {$username} / {$email}");
         return false;
     }
     return true;
 }
コード例 #6
0
    /**
     * Run the appropriate cron jobs based on the cron type.
     * @param string $type
     */
    public function cronjob($type)
    {
        // We need to run any normal hooks and not CLI hooks for this process if run from CLI
        $host_changed = false;
        if (!array_key_exists('HTTP_HOST', $_SERVER)) {
            $host_changed = true;
            $_SERVER['HTTP_HOST'] = '';
        }
        // Find all the Module Access modules that are available so the user can be set.
        $report_limits = I2CE_ModuleFactory::callHooks("get_report_module_limit_options");
        $limit_modules = array();
        foreach ($report_limits as $limit) {
            if (array_key_exists('module', $limit)) {
                $mod = I2CE_ModuleFactory::instance()->getClass($limit['module']);
                $limit_modules[] = array('module' => $mod, 'user' => $mod->getUser());
            }
        }
        $cron_type_where = array('operator' => "FIELD_LIMIT", 'style' => 'equals', 'field' => 'cron_type', 'data' => array('value' => $type));
        $reports = I2CE_FormStorage::listFields('cron_report', array('parent', 'report_view'), false, $cron_type_where);
        foreach ($reports as $report) {
            $view = $report['report_view'];
            $user = I2CE_FormFactory::instance()->createContainer($report['parent']);
            // Set the user on all access modules to limit results.
            foreach ($limit_modules as $module) {
                $module['module']->setUser($user->user);
            }
            $_SESSION['user_name'] = $user->username;
            $page = new I2CE_Page_ShowReport(array(), array($view));
            $template = $page->getTemplate();
            $display = $page->getDesiredDisplays($view);
            $use_display = 'Default';
            if ($display[0] != 'PieChart') {
                $use_display = $display[0];
            }
            $displayObj = $page->instantiateDisplay($use_display, $view);
            $config = I2CE::getConfig()->modules->CustomReports->reportViews->{$view};
            $template->loadRootText("<span id='siteContent' />");
            $contentNode = $template->getElementById('siteContent');
            $attachments = array();
            $report_name = $config->display_name;
            $report_desc = $config->description;
            $report_limit = '';
            $generated = strftime('%c');
            switch ($use_display) {
                case "CrossTab":
                    if ($displayObj->isExport()) {
                        $export = $displayObj->generateExport($contentNode, false);
                        $html = false;
                        $attachments[] = array('type' => "text/csv; charset=UTF-8", 'data' => $export, 'name' => $this->getFileName($report_name) . ".csv");
                        break;
                    }
                    // If not export then fall through to the Default
                // If not export then fall through to the Default
                case "Default":
                    $displayObj->unsetPaging();
                    $displayObj->display($contentNode);
                    $report_limit = $displayObj->getReportLimitsDescription();
                    $css = I2CE::getFileSearch()->search('CSS', 'customReports_display_Default.css');
                    $report_css = file_get_contents($css);
                    $report_table = $template->getElementById('report_table');
                    $report_content = $template->doc->saveHTML($report_table);
                    $html = <<<EOF
<?xml version="1.0" encoding="utf-8"?>'
<!DOCTYPE html>
<html>
<head>
    <title>Automated Report: {$report_name}</title>
    <style type="text/css">
{$report_css}
    </style>
</head>
<body>
    <h1>{$report_name}</h1>
    <h2>{$report_desc}</h2>
    <h3>{$report_limit}</h3>
    <p>Generated on: {$generated}</p>
    {$report_content}
</body>
</html>
EOF;
                    break;
                case "PDF":
                    $pdf = $displayObj->getPDF($contentNode);
                    $pdf_data = $pdf->Output($report_name, 'S');
                    $html = false;
                    $attachments[] = array('type' => 'application/pdf', 'data' => $pdf_data, 'name' => $this->getFileName($report_name) . ".pdf");
                    break;
                case "Export":
                    $export = $displayObj->generateExport();
                    $html = false;
                    $attachments[] = array('type' => $displayObj->getContentType(true), 'data' => $export, 'name' => $displayObj->getFileName());
                    break;
                default:
                    I2CE::raiseError("Unknown display type used for report display for user cron reports.");
                    break;
            }
            $email = $user->email;
            // This is duplicated from the Default setting so it can be in the main mail message as well.
            // It isn't called earlier to avoid duplicate processing with the Default display.
            if (!$html && $report_limit == '') {
                $report_limit = $displayObj->getReportLimitsDescription();
            }
            $mail_msg = wordwrap("This is the automated report for {$report_name}:  {$report_desc}.\nLimits are: {$report_limit}\nGenerated on: {$generated}.");
            if (I2CE_Mailer::mail($email, array('Subject' => 'Automated Report: ' . $report_name), $mail_msg, $html, $attachments)) {
                echo "Report mail {$report_name} (" . $report['report_view'] . ") sent to {$email}.\n";
            } else {
                echo "Report mail {$report_name} (" . $report['report_view'] . ") failed to {$email}.\n";
            }
            //$page->actionCommandLine( array(), array() );
        }
        if ($host_changed) {
            unset($_SERVER['HTTP_HOST']);
        }
        unset($_SESSION['user_name']);
        foreach ($limit_modules as $module) {
            $module['module']->setUser($module['user']);
        }
    }