Ejemplo n.º 1
1
 /**
  * Download task list as attachment
  *
  * @access public
  * @param void
  * @return null
  */
 function download_list()
 {
     $task_list = ProjectTaskLists::findById(get_id());
     if (!$task_list instanceof ProjectTaskList) {
         flash_error(lang('task list dnx'));
         $this->redirectTo('task');
     }
     // if
     $this->canGoOn();
     if (!$task_list->canView(logged_user())) {
         flash_error(lang('no access permissions'));
         $this->redirectToReferer(get_url('task'));
     }
     // if
     $output = array_var($_GET, 'output', 'csv');
     $project_name = active_project()->getName();
     $task_list_name = $task_list->getName();
     $task_count = 0;
     if ($output == 'pdf') {
         Env::useLibrary('fpdf');
         $download_name = "{$project_name}-{$task_list_name}-tasks.pdf";
         $download_type = 'application/pdf';
         $pdf = new FPDF();
         $pdf->AddPage();
         $pdf->SetTitle($task_list_name);
         $pdf->SetCompression(true);
         $pdf->SetCreator('ProjectPier');
         $pdf->SetDisplayMode(fullpage, single);
         $pdf->SetSubject(active_project()->getObjectName());
         $pdf->SetFont('Arial', 'B', 16);
         $task_lists = active_project()->getOpenTaskLists();
         $pdf->Cell(0, 10, lang('project') . ': ' . active_project()->getObjectName(), 'C');
         $pdf->Ln();
         foreach ($task_lists as $task_list) {
             $pdf->SetFont('Arial', 'B', 14);
             $pdf->Write(10, lang('task list') . ': ' . $task_list->getObjectName());
             $pdf->Ln();
             $tasks = $task_list->getTasks();
             $line = 0;
             // Column widths
             $w = array(10, 0, 0);
             // Header
             //for($i=0;$i<count($header);$i++)
             //  $this->Cell($w[$i],7,$header[$i],1,0,'C');
             //$this->Ln();
             $pdf->SetFont('Arial', 'I', 14);
             foreach ($tasks as $task) {
                 $line++;
                 if ($task->isCompleted()) {
                     $task_status = lang('completed');
                     $pdf->SetTextColor(100, 200, 100);
                     $task_completion_info = lang('completed task') . ' : ' . format_date($task->getCompletedOn());
                 } else {
                     $task_status = lang('open');
                     $pdf->SetTextColor(255, 0, 0);
                     $task_completion_info = lang('due date') . ' : ' . lang('not assigned');
                     if ($task->getDueDate()) {
                         $task_completion_info = lang('due date') . ' : ' . format_date($task->getDueDate());
                     }
                 }
                 if ($task->getAssignedTo()) {
                     $task_assignee = $task->getAssignedTo()->getObjectName();
                 } else {
                     $task_assignee = lang('not assigned');
                 }
                 $pdf->Cell($w[0], 6, $line);
                 $pdf->Cell($w[2], 6, $task_status, "TLRB");
                 $pdf->Ln();
                 $pdf->Cell($w[0], 6, '');
                 $pdf->SetTextColor(0, 0, 0);
                 $pdf->Cell($w[2], 6, $task_completion_info, "TLRB");
                 $pdf->Ln();
                 $pdf->Cell($w[0], 6, '');
                 $pdf->SetTextColor(0, 0, 0);
                 $pdf->Cell($w[2], 6, $task_assignee, "TLRB");
                 $pdf->Ln();
                 $pdf->Cell($w[0], 6, '');
                 $pdf->SetTextColor(0, 0, 0);
                 $pdf->MultiCell($w[2], 6, $task->getText(), "TLRB");
                 $pdf->Ln();
             }
         }
         $pdf->Output($download_name, 'D');
     } else {
         $download_name = "{$project_name}-{$task_list_name}-tasks.txt";
         $download_type = 'text/csv';
         $download_contents = $task_list->getDownloadText($task_count, "\t", true);
         download_contents($download_contents, $download_type, $download_name, strlen($download_contents));
     }
     die;
 }
Ejemplo n.º 2
0
/**
 * Just textile the text and return
 *
 * @param string $text Input text
 * @return string
 */
function do_textile($text)
{
    Env::useLibrary('textile');
    $textile = new Textile();
    $text = $textile->TextileRestricted($text, false, false);
    return add_links($text);
}
Ejemplo n.º 3
0
 function diff()
 {
     $page = Wiki::getPageById(get_id(), active_project());
     if (!instance_of($page, 'WikiPage')) {
         flash_error('wiki page dnx');
         $this->redirectTo('wiki');
     }
     // if
     if (!$page->canView(logged_user())) {
         flash_error('no access permissions');
         $this->redirectTo('wiki');
     }
     // if
     $rev1 = $page->getRevision(array_var($_GET, 'rev1', -1));
     $rev2 = $page->getRevision(array_var($_GET, 'rev2', -1));
     if (!instance_of($rev1, 'Revision') || !instance_of($rev2, 'Revision')) {
         flash_error(lang('wiki page revision dnx'));
         $this->redirectTo('wiki');
     }
     // if
     $this->addHelper('textile');
     //Load text diff library
     Env::useLibrary('diff', 'wiki');
     $diff = new diff($rev1->getContent(), $rev2->getContent());
     $output = new diff_renderer_inline();
     tpl_assign('diff', $output->render($diff));
     tpl_assign('page', $page);
     tpl_assign('revision', $page->getLatestRevision());
     tpl_assign('rev1', $rev1);
     tpl_assign('rev2', $rev2);
 }
Ejemplo n.º 4
0
 private function generatePictureFile($source_file, $max_size, $tmp_filename = "")
 {
     if (!$tmp_filename) {
         $tmp_filename = CACHE_DIR . "/" . gen_id() . ".png";
     }
     if (!is_file($source_file)) {
         return null;
     }
     if (!$max_size) {
         $max_size = 600;
     }
     Env::useLibrary('simplegd');
     $image = new SimpleGdImage($source_file);
     if ($image->getWidth() > $max_size || $image->getHeight() > $max_size) {
         if ($image->getWidth() > $image->getHeight()) {
             $w = $max_size;
             $ratio = $image->getHeight() / $image->getWidth();
             $h = $ratio * $w;
         } else {
             $h = $max_size;
             $ratio = $image->getWidth() / $image->getHeight();
             $w = $ratio * $h;
         }
         $new_image = $image->resize($w, $h, false);
         $new_image->saveAs($tmp_filename);
         $repo_id = FileRepository::addFile($tmp_filename, array('type' => 'image/png', 'public' => true));
         @unlink($tmp_filename);
         return $repo_id;
     } else {
         return null;
     }
 }
Ejemplo n.º 5
0
 /**
  * Send an email using Swift (send commands)
  * 
  * @param string to_address
  * @param string from_address
  * @param string subject
  * @param string body, optional
  * @param string content-type,optional
  * @param string content-transfer-encoding,optional
  * @return bool successful
  */
 static function sendEmail($to, $from, $subject, $body = false, $type = 'text/plain', $encoding = '8bit')
 {
     Env::useLibrary('swift');
     $mailer = self::getMailer();
     if (!$mailer instanceof Swift) {
         throw new NotifierConnectionError();
     }
     // if
     $result = $mailer->send($to, $from, $subject, $body, $type, $encoding);
     $mailer->close();
     return $result;
 }
Ejemplo n.º 6
0
 function getContent($smtp_server, $smtp_port, $transport, $smtp_username, $smtp_password, $body, $attachments)
 {
     //Load in the files we'll need
     Env::useLibrary('swift');
     switch ($transport) {
         case 'ssl':
             $transport = SWIFT_SSL;
             break;
         case 'tls':
             $transport = SWIFT_TLS;
             break;
         default:
             $transport = 0;
             break;
     }
     //Start Swift
     $mailer = new Swift(new Swift_Connection_SMTP($smtp_server, $smtp_port, $transport));
     if (!$mailer->isConnected()) {
         return false;
     }
     // if
     $mailer->setCharset('UTF-8');
     if ($smtp_username != null) {
         if (!$mailer->authenticate($smtp_username, self::ENCRYPT_DECRYPT($smtp_password))) {
             return false;
         }
     }
     if (!$mailer->isConnected()) {
         return false;
     }
     // add attachments
     $mailer->addPart($body);
     // real body
     if (is_array($attachments) && count($attachments) > 0) {
         foreach ($attachments as $att) {
             $mailer->addAttachment($att["data"], $att["name"], $att["type"]);
         }
     }
     $content = $mailer->getFullContent(false);
     $mailer->close();
     return $content;
 }
Ejemplo n.º 7
0
 /**
  * Set contact picture from $source file
  *
  * @param string $source Source file
  * @param integer $max_width Max picture widht
  * @param integer $max_height Max picture height
  * @param boolean $save Save user object when done
  * @return string
  */
 function setPicture($source, $fileType, $max_width = 50, $max_height = 50, $save = true)
 {
     if (!is_readable($source)) {
         return false;
     }
     do {
         $temp_file = ROOT . '/cache/' . sha1(uniqid(rand(), true));
     } while (is_file($temp_file));
     Env::useLibrary('simplegd');
     $image = new SimpleGdImage($source);
     if ($image->getImageType() == IMAGETYPE_PNG) {
         if ($image->getHeight() > 128 || $image->getWidth() > 128) {
             //	resize images if are png bigger than 128 px
             $thumb = $image->scale($max_width, $max_height, SimpleGdImage::BOUNDARY_DECREASE_ONLY, false);
             $thumb->saveAs($temp_file, IMAGETYPE_PNG);
             $public_fileId = FileRepository::addFile($temp_file, array('type' => 'image/png', 'public' => true));
         } else {
             //keep the png as it is.
             $public_fileId = FileRepository::addFile($source, array('type' => 'image/png', 'public' => true));
         }
     } else {
         $thumb = $image->scale($max_width, $max_height, SimpleGdImage::BOUNDARY_DECREASE_ONLY, false);
         $thumb->saveAs($temp_file, IMAGETYPE_PNG);
         $public_fileId = FileRepository::addFile($temp_file, array('type' => 'image/png', 'public' => true));
     }
     if ($public_fileId) {
         $this->setPictureFile($public_fileId);
         if ($save) {
             $this->save();
         }
         // if
     }
     // if
     $result = true;
     // Cleanup
     if (!$result && $public_fileId) {
         FileRepository::deleteFile($public_fileId);
     }
     // if
     @unlink($temp_file);
     return $result;
 }
Ejemplo n.º 8
0
 /**
  * Download task list as attachment
  *
  * @access public
  * @param void
  * @return null
  */
 function download()
 {
     $project = active_project();
     //$times = $project->getTimes();
     $times = ProjectTimes::findAll(array('conditions' => array('`project_id` = ?', $project->getId()), 'order' => '`done_date` DESC'));
     if (!is_array($times)) {
         flash_error(lang('time dnx'));
         $this->redirectTo('time');
     }
     // if
     $this->canGoOn();
     $filtered = array();
     foreach ($times as $time) {
         if ($time->canView(logged_user())) {
             $filtered[] = $time;
         }
     }
     // if
     $times = null;
     $output = array_var($_GET, 'output', 'csv');
     $project_name = active_project()->getName();
     $task_count = 0;
     if ($output == 'pdf') {
         Env::useLibrary('fpdf');
         $download_name = "{$project_name}-times.pdf";
         $download_type = 'application/pdf';
         $pdf = new FPDF();
         $pdf->AddPage();
         $pdf->SetTitle($project_name);
         $pdf->SetFont('Arial', 'B', 16);
         $task_lists = active_project()->getOpenTaskLists();
         $pdf->Cell(0, 10, lang('project') . ': ' . active_project()->getObjectName(), 'C');
         $pdf->Ln();
         $w = array(0 => 6, 140, 140);
         $pdf->SetFont('Arial', 'I', 14);
         foreach ($filtered as $time) {
             $line++;
             $time_id = '' . $time->getId();
             $time_done = format_date($time->getDoneDate(), null, 0);
             if ($time->getIsClosed()) {
                 $time_status = lang('completed');
                 $time_completion_info = format_date($task->getUpdatedOn());
             } else {
                 $time_status = lang('open');
                 $time_completion_info = '                ';
             }
             if ($time->getAssignedTo()) {
                 $time_assignee = $time->getAssignedTo()->getObjectName();
             } else {
                 $time_assignee = lang('not assigned');
             }
             $pdf->Cell($w[0], 6, $line);
             $pdf->Cell($w[1], 6, $time_id . " / " . $time_status . " / " . $time_completion_info . " / " . $time_assignee . " / " . $time_done, "TLRB");
             $pdf->Ln();
             $pdf->Cell($w[0], 6, '');
             $pdf->MultiCell($w[2], 6, $time->getDescription());
             $pdf->Ln();
         }
         $pdf->Output($download_name, 'D');
     } else {
         $download_name = "{$project_name}-times.txt";
         $download_type = 'text/csv';
         $s = "Project name\tId\tDate\tDescription\tHours\tBillable\n";
         foreach ($filtered as $time) {
             $s .= $project_name;
             $s .= "\t";
             $s .= $time->getId();
             $s .= "\t";
             $s .= format_date($time->getDoneDate(), null, 0);
             $s .= "\t";
             $s .= $time->getDescription();
             $s .= "\t";
             $s .= $time->getHours();
             $s .= "\t";
             $s .= $time->getIsBillable();
             $s .= "\n";
         }
         $download_contents = $s;
         download_headers($download_name, $download_type, strlen($download_contents), true);
         echo $download_contents;
     }
     die;
 }
Ejemplo n.º 9
0
 /**
  * Set logo value
  *
  * @param string $source Source file
  * @param integer $max_width
  * @param integer $max_height
  * @param boolean $save Save object when done
  * @return null
  */
 function setLogo($source, $max_width = 50, $max_height = 50, $save = true)
 {
     if (!is_readable($source)) {
         return false;
     }
     do {
         $temp_file = ROOT . '/cache/' . sha1(uniqid(rand(), true));
     } while (is_file($temp_file));
     try {
         Env::useLibrary('simplegd');
         $image = new SimpleGdImage($source);
         $thumb = $image->scale($max_width, $max_height, SimpleGdImage::BOUNDARY_DECREASE_ONLY, false);
         $thumb->saveAs($temp_file, IMAGETYPE_PNG);
         $public_filename = PublicFiles::addFile($temp_file, 'png');
         if ($public_filename) {
             $this->setLogoFile($public_filename);
             if ($save) {
                 $this->save();
             }
             // if
         }
         // if
         $result = true;
     } catch (Exception $e) {
         $result = false;
     }
     // try
     // Cleanup
     if (!$result && $public_filename) {
         PublicFiles::deleteFile($public_filename);
     }
     // if
     @unlink($temp_file);
     return $result;
 }
Ejemplo n.º 10
0
/**
 * Just textile the text and return
 *
 * @param string $text Input text
 * @param boolean $lite Skip lists, tables and blocks
 * @param boolean $encode Encode and return
 * @param boolean $noimage Don't insert images
 * @param boolean $strict Fix entities and fix whitespace
 * @param string $rel
 * @return string
 */
function do_textile($text, $lite = false, $encode = false, $noimage = false, $strict = false, $rel = '')
{
    Env::useLibrary('textile');
    $textile = new Textile();
    return '<div class="textile-rewrite">' . $textile->TextileThis($text, $lite, $encode, $noimage, $strict, $rel) . '</div>';
}
Ejemplo n.º 11
0
function fodt2text($filename,$id) {    
    Env::useLibrary('ezcomponents');
    
    $odt = new ezcDocumentOdt();
    $odt->loadFile( $filename );

    $docbook = $odt->getAsDocbook();

    $converter = new ezcDocumentDocbookToRstConverter();
    $rst = $converter->convert( $docbook );
    
    $file_path_txt = 'tmp/fodt2text_' . $id . '.txt';
    file_put_contents( $file_path_txt, $rst );
    $content = file_get_contents($file_path_txt); //Guardamos archivo.txt en $archivo
    unlink($file_path_txt);
    return $content;
}
Ejemplo n.º 12
0
 /**
  * Send an email using Swift (send commands)
  * 
  * @param string to_address
  * @param string from_address
  * @param string subject
  * @param string body, optional
  * @param string content-type,optional
  * @param string content-transfer-encoding,optional
  * @return bool successful
  */
 static function sendEmail($to, $from, $subject, $body = false, $type = 'text/plain', $encoding = '8bit')
 {
     //static function sendEmail($to, $from, $subject, $body = false, $type = 'text/html', $encoding = '') {
     Env::useLibrary('swift');
     $mailer = self::getMailer();
     if (!$mailer instanceof Swift) {
         throw new NotifierConnectionError();
     }
     // if
     /** 
      * Set name address in ReplyTo, some MTA think we're usurpators
      * (which is quite true actually...)
      */
     if (config_option('mail_use_reply_to', 0) == 1) {
         $i = strpos($from, ' <');
         $name = '?';
         if ($i !== false) {
             $name = substr($from, 0, $i);
         }
         $mailer->setReplyTo($from);
         $mail_from = trim(config_option('mail_from'));
         if ($mail_from == '') {
             $mail_from = 'projectpier@' . $_SERVER['SERVER_NAME'];
         }
         $from = "{$name} <{$mail_from}>";
     }
     // from must be address known on server when authentication is selected
     $smtp_authenticate = config_option('smtp_authenticate', false);
     if ($smtp_authenticate) {
         $from = config_option('smtp_username');
     }
     trace("mailer->send({$to}, {$from}, {$subject}, {$body}, {$type}, {$encoding})");
     $result = $mailer->send($to, $from, $subject, $body, $type, $encoding);
     $mailer->close();
     return $result;
 }
Ejemplo n.º 13
0
<?php

Env::useLibrary('openflashchart');
function render_pie_chart($options)
{
    $values = array();
    $colours = array();
    if (is_array($options['data'])) {
        foreach ($options['data'] as $data) {
            //	$values[]  = new OFC_Charts_Pie_Value($data['value'], $data['text']) ;
            $value = new OFC_Charts_Pie_Value($data['value'], $data['text']);
            $value->label = $data['text'];
            $values[] = $value;
            $colours[] = $data['color'];
        }
    }
    $chart = new OFC_Chart();
    $chart->set_bg_colour(array_var($options, 'background-color', '#FFFFFF'));
    $chart->set_title(new OFC_Elements_Title(array_var($options, 'title', "")));
    $pie = new OFC_Charts_Pie();
    if (array_var($options, 'start_angle')) {
        $pie->set_start_angle(array_var($options, 'start_angle'));
    }
    $pie->tip = array_var($options, 'tip') ? array_var($options, 'tip') : "#val#/#total#<br>#percent#";
    $pie->values = $values;
    $pie->colours = $colours;
    $pie->alpha = array_var($options, 'alpha') ? array_var($options, 'alpha') : 0.7;
    $pie->set_animate(array_var($options, 'animate', true));
    $chart->add_element($pie);
    $chart->x_axis = null;
    $filename = 'tmp/' . gen_id() . '.json';
Ejemplo n.º 14
0
 /**
  * Send an email using Swift (send commands)
  * 
  * @param string to_address
  * @param string from_address
  * @param string subject
  * @param string body, optional
  * @param string content-type,optional
  * @param string content-transfer-encoding,optional
  * @return bool successful
  */
 static function sendEmail($to, $from, $subject, $body = false, $type = 'text/plain', $encoding = '8bit')
 {
     //static function sendEmail($to, $from, $subject, $body = false, $type = 'text/html', $encoding = '') {
     Env::useLibrary('swift');
     $mailer = self::getMailer();
     if (!$mailer instanceof Swift) {
         throw new NotifierConnectionError();
     }
     // if
     /** 
      * If the 'expose user e-mail' flag is cleared, then replace the user's
      * email with the site e-mail.
      */
     if (config_option('mail_expose_user_emails', 0) == 0) {
         $from = self::getSiteEmailAddress();
     } elseif (config_option('mail_use_reply_to', 0) == 1) {
         $i = strpos($from, ' <');
         $name = '';
         if ($i !== false) {
             $name = substr($from, 0, $i);
         }
         $mailer->setReplyTo($from);
         $from = self::getSiteEmailAddress($name);
     }
     // from must be address known on server when authentication is selected
     $smtp_authenticate = config_option('smtp_authenticate', false);
     if ($smtp_authenticate) {
         $from = config_option('smtp_username');
     }
     trace("mailer->send({$to}, {$from}, {$subject}, {$body}, {$type}, {$encoding})");
     $result = $mailer->send($to, $from, $subject, $body, $type, $encoding);
     $mailer->close();
     return $result;
 }
Ejemplo n.º 15
0
 static function sendQueuedEmails()
 {
     $date = DateTimeValueLib::now();
     $date->add("d", -2);
     $emails = QueuedEmails::getQueuedEmails($date);
     if (count($emails) <= 0) {
         return 0;
     }
     Env::useLibrary('swift');
     $mailer = self::getMailer();
     if (!$mailer instanceof Swift_Mailer) {
         throw new NotifierConnectionError();
     }
     // if
     $fromSMTP = config_option("mail_transport", self::MAIL_TRANSPORT_MAIL) == self::MAIL_TRANSPORT_SMTP && config_option("smtp_authenticate", false);
     $count = 0;
     foreach ($emails as $email) {
         try {
             $body = $email->getBody();
             $subject = $email->getSubject();
             Hook::fire('notifier_email_body', $body, $body);
             Hook::fire('notifier_email_subject', $subject, $subject);
             if ($fromSMTP && config_option("smtp_address")) {
                 $pos = strrpos($email->getFrom(), "<");
                 if ($pos !== false) {
                     $sender_name = trim(substr($email->getFrom(), 0, $pos));
                 } else {
                     $sender_name = "";
                 }
                 $from = array(config_option("smtp_address") => $sender_name);
             } else {
                 $pos = strrpos($email->getFrom(), "<");
                 if ($pos !== false) {
                     $sender_name = trim(substr($email->getFrom(), 0, $pos));
                     $sender_address = str_replace(array("<", ">"), array("", ""), trim(substr($email->getFrom(), $pos, strlen($email->getFrom()) - 1)));
                 } else {
                     $sender_name = "";
                     $sender_address = $email->getFrom();
                 }
                 $from = array($sender_address => $sender_name);
             }
             $message = Swift_Message::newInstance($subject)->setFrom($from)->setBody($body)->setContentType('text/html');
             if ($email->columnExists('attachments')) {
                 $attachments = json_decode($email->getColumnValue('attachments'));
                 foreach ($attachments as $a) {
                     // if file does not exists or its size is greater than 20 MB then don't process the atachments
                     if (!file_exists($a->path) || filesize($a->path) / (1024 * 1024) > 20) {
                         continue;
                     }
                     $attach = Swift_Attachment::fromPath($a->path, $a->type);
                     $attach->setDisposition($a->disposition);
                     if ($a->cid) {
                         $attach->setId($a->cid);
                     }
                     if ($a->name) {
                         $attach->setFilename($a->name);
                     }
                     $message->attach($attach);
                 }
             }
             $to = prepare_email_addresses(implode(",", explode(";", $email->getTo())));
             foreach ($to as $address) {
                 $message->addTo(array_var($address, 0), array_var($address, 1));
             }
             $cc = prepare_email_addresses(implode(",", explode(";", $email->getCc())));
             foreach ($cc as $address) {
                 $message->addCc(array_var($address, 0), array_var($address, 1));
             }
             $bcc = prepare_email_addresses(implode(",", explode(";", $email->getBcc())));
             foreach ($bcc as $address) {
                 $message->addBcc(array_var($address, 0), array_var($address, 1));
             }
             $result = $mailer->send($message);
             if ($result) {
                 DB::beginWork();
                 // save notification history after cron sent the email
                 self::saveNotificationHistory(array('email_object' => $email));
                 // delte from queued_emails
                 $email->delete();
                 DB::commit();
             }
             $count++;
         } catch (Exception $e) {
             DB::rollback();
             // save log in server
             if (defined('EMAIL_ERRORS_LOGDIR') && file_exists(EMAIL_ERRORS_LOGDIR) && is_dir(EMAIL_ERRORS_LOGDIR)) {
                 $err_msg = ROOT_URL . "\nError sending notification (queued_email_id=" . $email->getId() . ") using account " . print_r($from, 1) . "\n\nError detail:\n" . $e->getMessage() . "\n" . $e->getTraceAsString();
                 file_put_contents(EMAIL_ERRORS_LOGDIR . basename(ROOT), $err_msg, FILE_APPEND);
             }
             Logger::log("There has been a problem when sending the Queued emails.\nError Message: " . $e->getMessage() . "\nTrace: " . $e->getTraceAsString());
             $msg = $e->getMessage();
             if (strpos($msg, 'Failed to authenticate') !== false) {
                 $from_k = array_keys($from);
                 $usu = Contacts::getByEmail($from_k[0]);
                 $rem = ObjectReminders::instance()->findOne(array('conditions' => "context='eauthfail " . $from_k[0] . "'"));
                 if (!$rem instanceof ObjectReminder && $usu instanceof Contact) {
                     $reminder = new ObjectReminder();
                     $reminder->setMinutesBefore(0);
                     $reminder->setType("reminder_popup");
                     $reminder->setContext("eauthfail " . $from_k[0]);
                     $reminder->setObject($usu);
                     $reminder->setUserId($usu->getId());
                     $reminder->setDate(DateTimeValueLib::now());
                     $reminder->save();
                 }
             }
         }
     }
     return $count;
 }
Ejemplo n.º 16
0
    }
    session_start();
    // Start the session
}
include_once ENVIRONMENT_PATH . '/classes/Env.class.php';
include_once ENVIRONMENT_PATH . '/constants.php';
include_once ENVIRONMENT_PATH . '/functions/utf.php';
include_once ENVIRONMENT_PATH . '/functions/general.php';
include_once ENVIRONMENT_PATH . '/functions/files.php';
// Remove slashes is magic quotes gpc is on from $_GET, $_POST and $_COOKIE
fix_input_quotes();
// Debug
if (Env::isDebugging()) {
    include_once ENVIRONMENT_PATH . '/classes/debug/BenchmarkTimer.class.php';
    benchmark_timer_start();
    benchmark_timer_set_marker('Init environment');
}
// if
// Include autoloader...
include ENVIRONMENT_PATH . '/classes/AutoLoader.class.php';
include ENVIRONMENT_PATH . '/classes/template/template.php';
include ENVIRONMENT_PATH . '/classes/flash/flash.php';
include ENVIRONMENT_PATH . '/classes/localization/localization.php';
include ENVIRONMENT_PATH . '/classes/logger/Logger_Entry.class.php';
include ENVIRONMENT_PATH . '/classes/logger/Logger_Session.class.php';
include ENVIRONMENT_PATH . '/classes/logger/Logger_Backend.class.php';
include ENVIRONMENT_PATH . '/classes/logger/Logger.class.php';
include ENVIRONMENT_PATH . '/classes/logger/backend/Logger_Backend_File.class.php';
// Init libraries
Env::useLibrary('database');
Ejemplo n.º 17
0
	static function sendQueuedEmails() {
		$date = DateTimeValueLib::now();
		$date->add("d", -2);
		$emails = QueuedEmails::getQueuedEmails($date);
		if (count($emails) <= 0) return 0;
		
		Env::useLibrary('swift');
		$mailer = self::getMailer();
		if(!($mailer instanceof Swift_Mailer)) {
			throw new NotifierConnectionError();
		} // if
		$fromSMTP = config_option("mail_transport", self::MAIL_TRANSPORT_MAIL) == self::MAIL_TRANSPORT_SMTP && config_option("smtp_authenticate", false);
		$count = 0;
		foreach ($emails as $email) {
			try {
				
				$body = $email->getBody();
				$subject = $email->getSubject();
				Hook::fire('notifier_email_body', $body, $body);
				Hook::fire('notifier_email_subject', $subject, $subject);
				
				if ($fromSMTP && config_option("smtp_address")) {
					$pos = strrpos($email->getFrom(), "<");
					if ($pos !== false) {
						$sender_name = trim(substr($email->getFrom(), 0, $pos));
					} else {
						$sender_name = "";
					}
					$from = array(config_option("smtp_address") => $sender_name);
				} else {
					$pos = strrpos($email->getFrom(), "<");
					if ($pos !== false) {
						$sender_name = trim(substr($email->getFrom(), 0, $pos));
						$sender_address = str_replace(array("<",">"),array("",""), trim(substr($email->getFrom(), $pos, strlen($email->getFrom())-1)));
					} else {
						$sender_name = "";
						$sender_address = $email->getFrom();
					}
					$from = array($sender_address => $sender_name);
				}
				$message = Swift_Message::newInstance($subject)
				  ->setFrom($from)
				  ->setBody($body)
				  ->setContentType('text/html')
				;
				
				if ($email->columnExists('attachments')) {
					$attachments = json_decode($email->getColumnValue('attachments'));
					foreach ($attachments as $a) {
						$attach = Swift_Attachment::fromPath($a->path, $a->type);
						$attach->setDisposition($a->disposition);
						if ($a->cid) $attach->setId($a->cid);
						if ($a->name) $attach->setFilename($a->name);
						$message->attach($attach);
					}
				}
				
				$to = prepare_email_addresses(implode(",", explode(";", $email->getTo())));
				foreach ($to as $address) {
					$message->addTo(array_var($address, 0), array_var($address, 1));
				}
				$result = $mailer->send($message);

				DB::beginWork();
				$email->delete();
				DB::commit();
				$count++;
			} catch (Exception $e) {
				DB::rollback();
				Logger::log('There has been a problem when sending the Queued emails. Problem:'.$e->getTraceAsString());
			}
		}
		return $count;
	}
 /**
  * Create image thumbnail. This function will return true on success, false otherwise
  *
  * @param void
  * @return boolean
  */
 protected function createThumb()
 {
     do {
         $source_file = CACHE_DIR . '/' . sha1(uniqid(rand(), true));
     } while (is_file($source_file));
     if (!file_put_contents($source_file, $this->getFileContent()) || !is_readable($source_file)) {
         return false;
     }
     // if
     do {
         $temp_file = CACHE_DIR . '/' . sha1(uniqid(rand(), true));
     } while (is_file($temp_file));
     try {
         Env::useLibrary('simplegd');
         $image = new SimpleGdImage($source_file);
         $thumb = $image->scale(100, 100, SimpleGdImage::BOUNDARY_DECREASE_ONLY, false);
         $thumb->saveAs($temp_file, IMAGETYPE_PNG);
         $public_filename = PublicFiles::addFile($temp_file, 'png');
         if ($public_filename) {
             $this->setThumbFilename($public_filename);
             $this->save();
         }
         // if
         $result = true;
     } catch (Exception $e) {
         $result = false;
     }
     // try
     @unlink($source_file);
     @unlink($temp_file);
     return $result;
 }
 /**
  * Download task list as attachment
  *
  * @access public
  * @param void
  * @return null
  */
 function download_list()
 {
     $task_list = ProjectTaskLists::findById(get_id());
     if (!$task_list instanceof ProjectTaskList) {
         flash_error(lang('task list dnx'));
         $this->redirectTo('task');
     }
     // if
     $this->canGoOn();
     if (!$task_list->canView(logged_user())) {
         flash_error(lang('no access permissions'));
         $this->redirectToReferer(get_url('task'));
     }
     // if
     $output = array_var($_GET, 'output', 'csv');
     $project_name = active_project()->getName();
     $task_list_name = $task_list->getName();
     $task_count = 0;
     if ($output == 'pdf') {
         Env::useLibrary('fpdf');
         $download_name = "{$project_name}-tasks.pdf";
         $download_type = 'application/pdf';
         $pdf = new FPDF("P", "mm");
         $pdf->AddPage();
         $pdf->SetTitle($project_name);
         $pdf->SetCompression(true);
         $pdf->SetCreator('ProjectPier');
         $pdf->SetDisplayMode('fullpage', 'single');
         $pdf->SetSubject(active_project()->getObjectName());
         $pdf->SetFont('Arial', 'B', 16);
         $task_lists = active_project()->getOpenTaskLists();
         $pdf->Cell(0, 10, lang('project') . ': ' . active_project()->getObjectName(), 'B', 0, 'C');
         $pdf->Ln(14);
         $w = array(0 => 12, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 120, 140);
         foreach ($task_lists as $task_list) {
             $pdf->SetFont('Arial', 'B', 14);
             $pdf->Write(10, lang('task list') . ': ' . $task_list->getObjectName());
             $pdf->Ln(14);
             $tasks = $task_list->getTasks();
             $pdf->SetFont('Arial', 'I', 14);
             $pdf->SetFillColor(230, 230, 230);
             $pdf->Cell($w[1], 6, '#', 1, 0, 'C', true);
             $pdf->Cell($w[3], 6, lang('status'), 1, 0, 'C', true);
             $pdf->Cell($w[10], 6, lang('info'), 1, 0, 'C', true);
             $pdf->Cell(0, 6, lang(user), 1, 0, 'C', true);
             $pdf->Ln();
             foreach ($tasks as $task) {
                 $line++;
                 if ($task->isCompleted()) {
                     $task_status = lang('completed');
                     $task_status_color_R = 0;
                     $task_status_color_G = 150;
                     $task_status_color_B = 0;
                     $task_completion_info = lang('completed task') . ' : ' . format_date($task->getCompletedOn()) . ' @ ' . format_time($task->getCompletedOn());
                 } else {
                     $task_status = lang('open');
                     $task_status_color_R = 200;
                     $task_status_color_G = 0;
                     $task_status_color_B = 0;
                     $task_completion_info = lang('due date') . ' : ' . lang('not assigned');
                     $task_completion_info_color_R = 200;
                     $task_completion_info_color_G = 0;
                     $task_completion_info_color_B = 0;
                     if ($task->getDueDate()) {
                         $task_completion_info = lang('due date') . ' : ' . format_date($task->getDueDate()) . ' @ ' . format_time($task->getDueDate());
                         $task_completion_info_color_R = 0;
                         $task_completion_info_color_G = 0;
                         $task_completion_info_color_B = 0;
                     }
                 }
                 if ($task->getAssignedTo()) {
                     $task_assignee = $task->getAssignedTo()->getObjectName();
                     $task_assignee_color_R = 0;
                     $task_assignee_color_G = 0;
                     $task_assignee_color_B = 0;
                 } else {
                     $task_assignee = lang('not assigned');
                     $task_assignee_color_R = 200;
                     $task_assignee_color_G = 0;
                     $task_assignee_color_B = 0;
                 }
                 $pdf->SetFillColor(245, 245, 245);
                 $pdf->Cell($w[1], 6, $line, 1, 0, 'C', true);
                 $pdf->SetTextColor($task_status_color_R, $task_status_color_G, $task_status_color_B);
                 $pdf->Cell($w[3], 6, $task_status, 1, 0, 'C', true);
                 $pdf->SetTextColor($task_completion_info_color_R, $task_completion_info_color_G, $task_completion_info_color_B);
                 $pdf->Cell($w[10], 6, $task_completion_info, 1, 0, 'C', true);
                 $pdf->SetTextColor($task_assignee_color_R, $task_assignee_color_G, $task_assignee_color_B);
                 $pdf->Cell(0, 6, $task_assignee, 1, 0, 'C', true);
                 $pdf->SetTextColor(0, 0, 0);
                 $pdf->Ln();
                 $pdf->MultiCell(0, 6, $task->getText(), 1);
                 //$pdf->Ln();
             }
         }
         $pdf->Output($download_name, 'I');
     }
     if ($output == 'txt') {
         $download_name = "{$project_name}-tasks.txt";
         $download_type = 'text/csv';
         $txt_lang_1 = lang('project');
         $txt_lang_2 = lang('milestone');
         $txt_lang_3 = lang('task list');
         $txt_lang_4 = lang('status');
         $txt_lang_5 = lang('description');
         $txt_lang_6 = lang('id');
         $txt_lang_7 = lang('status');
         $txt_lang_8 = lang('completion info');
         $txt_lang_9 = lang('assigned to');
         $s .= "{$txt_lang_1}\t{$txt_lang_2}\t{$txt_lang_3}\t{$txt_lang_4}\t{$txt_lang_5}\t{$txt_lang_6}\t{$txt_lang_7}\t{$txt_lang_8}\t{$txt_lang_9}";
         $s .= "\n";
         $task_lists = active_project()->getOpenTaskLists();
         foreach ($task_lists as $task_list) {
             /*$s .= $task_list->getObjectName();
               $s .= "\n";
               $task_list_desc = $task_list->getDescription();
               $task_list_desc = strtr($task_list_desc,"\r\n\t","   ");
               $task_list_desc_100 = substr($task_list_desc,0,100);
               $s .= $task_list_desc_100;
               $s .= "\n";*/
             $milestone = $task_list->getMilestone();
             $tasks = $task_list->getTasks();
             foreach ($tasks as $task) {
                 $s .= $project_name;
                 $s .= "\t";
                 $milestone_name = lang(none);
                 if ($milestone instanceof ProjectMilestone) {
                     $milestone_name = $milestone->getName();
                 }
                 $s .= $milestone_name;
                 $s .= "\t";
                 $s .= $task_list->getObjectName();
                 $s .= "\t";
                 $task_list_name = $task_list->getName();
                 if ($task_list->isCompleted()) {
                     $task_list_status = lang('completed');
                 } else {
                     $task_list_status = lang('open');
                 }
                 $s .= $task_list_status;
                 $s .= "\t";
                 $task_list_desc2 = $task_list->getDescription();
                 $task_list_desc2 = strtr($task_list_desc2, "\r\n\t", "   ");
                 $task_list_desc2_100 = substr($task_list_desc2, 0, 50);
                 $s .= $task_list_desc2_100;
                 $s .= "\t";
                 $s .= $task->getId();
                 $s .= "\t";
                 if ($task->isCompleted()) {
                     $task_status = lang('completed');
                     $task_completion_info = format_date($task->getCompletedOn()) . " @ " . format_time($task->getCompletedOn());
                 } else {
                     $task_status = lang('open');
                     $task_completion_info = format_date($task->getDueDate()) . " @ " . format_time($task->getDueDate());
                 }
                 $s .= $task_status;
                 $s .= "\t";
                 $s .= $task_completion_info;
                 $s .= "\t";
                 if ($task->getAssignedTo()) {
                     $task_assignee = $task->getAssignedTo()->getObjectName();
                 } else {
                     $task_assignee = lang('not assigned');
                 }
                 $s .= $task_assignee;
                 $s .= "\n";
             }
         }
         $download_contents = $s;
         download_headers($download_name, $download_type, strlen($download_contents), true);
         echo $download_contents;
     } else {
         $download_name = "{$project_name}-{$task_list_name}-tasks.csv";
         $download_type = 'text/csv';
         $download_contents = $task_list->getDownloadText($task_count, "\t", true);
         download_contents($download_contents, $download_type, $download_name, strlen($download_contents));
     }
     die;
 }