Esempio n. 1
0
 private function truncate($string)
 {
     if (preg_match('/[^0-9]/', $string)) {
         $string = utf8_truncate($string, 11, '');
     } else {
         $string = substr($string, 0, 15);
     }
     return $string;
 }
Esempio n. 2
0
 function GetMessage($folderid, $id, $truncsize, $mimesupport = 0)
 {
     debugLog("IMAP-GetMessage: (fid: '{$folderid}'  id: '{$id}'  truncsize: {$truncsize})");
     // Get flags, etc
     $stat = $this->StatMessage($folderid, $id);
     if ($stat) {
         $this->imap_reopenFolder($folderid);
         $mail = @imap_fetchheader($this->_mbox, $id, FT_UID) . @imap_body($this->_mbox, $id, FT_PEEK | FT_UID);
         $mobj = new Mail_mimeDecode($mail);
         $message = $mobj->decode(array('decode_headers' => true, 'decode_bodies' => true, 'include_bodies' => true, 'charset' => 'utf-8'));
         $output = new SyncMail();
         $body = $this->getBody($message);
         $output->bodysize = strlen($body);
         // truncate body, if requested
         if (strlen($body) > $truncsize) {
             $body = utf8_truncate($body, $truncsize);
             $output->bodytruncated = 1;
         } else {
             $body = $body;
             $output->bodytruncated = 0;
         }
         $body = str_replace("\n", "\r\n", str_replace("\r", "", $body));
         $output->body = $body;
         $output->datereceived = isset($message->headers["date"]) ? $this->cleanupDate($message->headers["date"]) : null;
         $output->displayto = isset($message->headers["to"]) ? $message->headers["to"] : null;
         $output->importance = isset($message->headers["x-priority"]) ? preg_replace("/\\D+/", "", $message->headers["x-priority"]) : null;
         $output->messageclass = "IPM.Note";
         $output->subject = isset($message->headers["subject"]) ? $message->headers["subject"] : "";
         $output->read = $stat["flags"];
         $output->to = isset($message->headers["to"]) ? $message->headers["to"] : null;
         $output->cc = isset($message->headers["cc"]) ? $message->headers["cc"] : null;
         $output->from = isset($message->headers["from"]) ? $message->headers["from"] : null;
         $output->reply_to = isset($message->headers["reply-to"]) ? $message->headers["reply-to"] : null;
         // Attachments are only searched in the top-level part
         if (isset($message->parts)) {
             $mparts = $message->parts;
             for ($i = 0; $i < count($mparts); $i++) {
                 $part = $mparts[$i];
                 //recursively add parts
                 if ($part->ctype_primary == "multipart" && ($part->ctype_secondary == "mixed" || $part->ctype_secondary == "alternative" || $part->ctype_secondary == "related")) {
                     foreach ($part->parts as $spart) {
                         $mparts[] = $spart;
                     }
                     continue;
                 }
                 //add part as attachment if it's disposition indicates so or if it is not a text part
                 if (isset($part->disposition) && ($part->disposition == "attachment" || $part->disposition == "inline") || isset($part->ctype_primary) && $part->ctype_primary != "text") {
                     $attachment = new SyncAttachment();
                     if (isset($part->body)) {
                         $attachment->attsize = strlen($part->body);
                     }
                     if (isset($part->d_parameters['filename'])) {
                         $attname = $part->d_parameters['filename'];
                     } else {
                         if (isset($part->ctype_parameters['name'])) {
                             $attname = $part->ctype_parameters['name'];
                         } else {
                             if (isset($part->headers['content-description'])) {
                                 $attname = $part->headers['content-description'];
                             } else {
                                 $attname = "unknown attachment";
                             }
                         }
                     }
                     $attachment->displayname = $attname;
                     $attachment->attname = $folderid . ":" . $id . ":" . $i;
                     $attachment->attmethod = 1;
                     $attachment->attoid = isset($part->headers['content-id']) ? $part->headers['content-id'] : "";
                     array_push($output->attachments, $attachment);
                 }
             }
         }
         // unset mimedecoder & mail
         unset($mobj);
         unset($mail);
         return $output;
     }
     return false;
 }
Esempio n. 3
0
 function _getEmail($mapimessage, $truncsize, $bodypreference, $optionbodypreference, $mimesupport = 0)
 {
     $messageprops = mapi_getprops($mapimessage, array(PR_MESSAGE_CLASS, PR_LAST_VERB_EXECUTED, PR_LAST_VERB_EXECUTION_TIME, PR_CONVERSATION_INDEX));
     // Destinguish between SMS and eMail Messages. In case we have an SMS to sync
     // we need a SyncSMS Object that is in real a very much castrated SyncMail Object...
     // We even could create a separate _get function BUT since its Folderclass is email it
     // makes things easier to work just with one function. Except the Address Handling and
     // less fields everything else remains the same
     if (strtolower($messageprops[PR_MESSAGE_CLASS]) == 'ipm.note.mobile.sms') {
         $message = new SyncSMS();
         if (isset($optionbodypreference) && $optionbodypreference != false) {
             $bodypreference = $optionbodypreference;
         }
     } else {
         $message = new SyncMail();
     }
     if (isset($messageprops[PR_LAST_VERB_EXECUTED])) {
         switch ($messageprops[PR_LAST_VERB_EXECUTED]) {
             case 0x66:
                 $message->lastverbexecuted = 1;
                 break;
             case 0x67:
                 $message->lastverbexecuted = 2;
                 break;
             case 0x68:
                 $message->lastverbexecuted = 3;
                 break;
             default:
                 $message->lastverbexecuted = 0;
         }
         $message->lastverbexecutiontime = $messageprops[PR_LAST_VERB_EXECUTION_TIME];
     } else {
         $message->lastverbexecuted = 0;
     }
     $this->_getPropsFromMAPI($message, $mapimessage, $this->_emailmapping);
     // start added dw2412 AS V12.0 Flag support
     // should not break anything since in proto AS12 Fields get excluded in case a lower protocol is in use
     $message->poommailflag = new SyncPoommailFlag();
     $this->_getPropsFromMAPI($message->poommailflag, $mapimessage, $this->_emailflagmapping);
     if (!isset($message->poommailflag->flagstatus)) {
         $message->poommailflag->flagstatus = 0;
     }
     // end added dw2412 AS V12.0 Flag Support
     // dw2412 According to docs...
     if (!isset($message->contentclass) || $message->contentclass == "") {
         $message->contentclass = "urn:content-classes:message";
     }
     // Override 'body' for truncation
     // START CHANGED dw2412 Support Protocol Version 12 (added bodypreference compare)
     // We never the less transfer always UTF-8 so it should not matter to hardcode the internet cpid...
     // Other possible values are
     //
     // Name	                             Character Set   Code Page
     // Arabic (ISO)                      iso-8859-6      28596
     // Arabic (Windows)                  windows-1256    1256
     // Baltic (ISO)                      iso-8859-4      28594
     // Baltic (Windows)                  windows-1257    1257
     // Central European (ISO)            iso-8859-2      28592
     // Central European (Windows)        windows-1250    1250
     // Chinese Simplified (GB2312)       gb2312          936
     // Chinese Simplified (HZ)           hz-gb-2312      52936
     // Chinese Traditional (Big5)        big5            950
     // Cyrillic (ISO)                    iso-8859-5      28595
     // Cyrillic (KOI8-R)                 koi8-r          20866
     // Cyrillic (KOI8-U)                 koi8-u          21866
     // Cyrillic (Windows)                windows-1251    1251
     // Greek (ISO)                       iso-8859-7      28597
     // Greek (Windows)                   windows-1253    1253
     // Hebrew (ISO-Logical)              iso-8859-8-i    38598
     // Hebrew (Windows)                  windows-1255    1255
     // Japanese (EUC)                    euc-jp          51932
     // Japanese (JIS)                    iso-2022-jp     50220
     // Japanese (JIS-Allow 1 byte Kana)  csISO2022JP     50221
     // Japanese (Shift-JIS)              iso-2022-jp     932
     // Korean                            ks_c_5601-1987  949
     // Korean (EUC)                      euc-kr          51949
     // Latin 3 (ISO)                     iso-8859-3      28593
     // Latin 9 (ISO)                     iso-8859-15     28605
     // Thai (Windows)                    windows-874     874
     // Turkish (ISO)                     iso-8859-9      28599
     // Turkish (Windows)                 windows-1254    1254
     // Unicode (UTF-7)                   utf-7           65000
     // Unicode (UTF-8)                   utf-8           65001
     // US-ASCII                          us-ascii        20127
     // Vietnamese (Windows)              windows-1258    1258
     // Western European (ISO)            iso-8859-1      28591
     // Western European (Windows)        Windows-1252    1252
     //
     // For Compatibility with older Mailsystems
     //
     // Name	                             Character Set   Code Page
     // Arabic (Windows)                  windows-1256    1256
     // Baltic (ISO)                      iso-8859-4      28594
     // Central European (ISO)            iso-8859-2      28592
     // Chinese Simplified (GB2312)       gb2312          936
     // Chinese Traditional (Big5)        big5            950
     // Cyrillic (KOI8-R)                 koi8-r          20866
     // Cyrillic (Windows)                windows-1251    1251
     // Greek (ISO)                       iso-8859-7      28597
     // Hebrew (Windows)                  windows-1255    1255
     // Japanese (JIS)                    iso-2022-jp     50220
     // Korean                            ks_c_5601-1987  949
     // Thai (Windows)                    windows-874     874
     // Turkish (ISO)                     iso-8859-9      28599
     // Unicode (UTF-8)                   utf-8           65001
     // US-ASCII                          us-ascii        20127
     // Vietnamese (Windows)              windows-1258    1258
     // Western European (ISO)            iso-8859-1      28591
     if (!isset($message->internetcpid) || $message->internetcpid == "") {
         $message->internetcpid = 65001;
     }
     debugLog("_getemail: MimeSupport is " . $mimesupport);
     if ($bodypreference == false) {
         $body = mapi_openproperty($mapimessage, PR_BODY);
         $bodysize = strlen($body);
         if ($truncsize != false && $bodysize > $truncsize) {
             $body = substr($body, 0, $truncsize);
             $message->bodysize = $bodysize;
             $message->bodytruncated = 1;
         } else {
             $message->bodytruncated = 0;
         }
         $message->body = str_replace("\n", "\r\n", w2u(str_replace("\r", "", $body)));
         if (!isset($message->body) || strlen($message->body) == 0) {
             $message->body = " ";
         }
     } else {
         $rtf = mapi_message_openproperty($mapimessage, PR_RTF_COMPRESSED);
         if (!$rtf) {
             $message->airsyncbasenativebodytype = 1;
         } else {
             $rtf = preg_replace("/(\n.*)/m", "", mapi_decompressrtf($rtf));
             if (strpos($rtf, "\\fromtext") != false) {
                 $message->airsyncbasenativebodytype = 1;
             } else {
                 $message->airsyncbasenativebodytype = 2;
             }
         }
         if (!isset($bodypreference[1]["TruncationSize"])) {
             $bodypreference[1]["TruncationSize"] = 1024 * 1024;
         }
         if (isset($bodypreference[4]) && function_exists("mapi_inetmapi_imtoinet") && (!defined('ICS_IMTOINET_SEGFAULT') || ICS_IMTOINET_SEGFAULT === false)) {
             $addrBook = mapi_openaddressbook($this->_session);
             $mstream = mapi_inetmapi_imtoinet($this->_session, $addrBook, $mapimessage, array());
             $mstreamstat = mapi_stream_stat($mstream);
         }
         $message->airsyncbasebody = new SyncAirSyncBaseBody();
         debugLog("airsyncbasebody!");
         if (isset($bodypreference[4]) && isset($mstream) && ($mimesupport == 2 || $mimesupport == 1 && strtolower(substr($messageprops[PR_MESSAGE_CLASS], 0, 14)) == 'ipm.note.smime')) {
             $mstreamcontent = mapi_stream_read($mstream, MAX_EMBEDDED_SIZE);
             $message->airsyncbasebody->type = 4;
             if ($truncsize != false && isset($bodypreference[4]["TruncationSize"])) {
                 $hdrend = strpos("\r\n\r\n", $mstreamcontent);
                 $message->airsyncbasebody->data = utf8_truncate($mstreamcontent, $hdrend + $bodypreference[4]["TruncationSize"]);
             } else {
                 $message->airsyncbasebody->data = $mstreamcontent;
             }
             if (strlen($message->airsyncbasebody->data) < $mstreamstat["cb"]) {
                 $message->airsyncbasebody->truncated = 1;
             }
             $message->airsyncbasebody->estimateddatasize = strlen($mstreamcontent);
         } elseif (isset($bodypreference[3]) && $message->airsyncbasenativebodytype == 3) {
             $message->airsyncbasebody->type = 3;
             $rtf = mapi_openproperty($mapimessage, PR_RTF_COMPRESSED);
             $message->airsyncbasebody->data = base64_encode($rtf);
             $message->airsyncbasebody->estimateddatasize = strlen($rtf);
             debugLog("RTF Body!");
         } elseif (isset($bodypreference[2])) {
             $message->airsyncbasebody->type = 2;
             $html = mapi_openproperty($mapimessage, PR_HTML);
             if (strpos(strtoupper($html), "<HTML>") == 0 && strpos(strtoupper($html), "<HEAD>") == 0 && strpos(strtoupper($html), "<BODY>") == 0) {
                 debugLog("Malformed html message, (HTML, HEAD, BODY missing");
                 $html = '<HTML>' . '<HEAD>' . '<META NAME="Generator" CONTENT="Z-Push">' . '<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8">' . '</HEAD>' . '<BODY>' . iconv(getCodepageCharset($message->internetcpid), "utf-8", $html) . '</BODY></HTML>';
                 $message->internetcpid = 65001;
             } else {
                 if ($message->internetcpid != 65001) {
                     $html = iconv(getCodepageCharset($message->internetcpid), "utf-8", $html);
                 }
             }
             /* This should be removed 110422
             			if ($message->airsyncbasenativebodytype==2) {
             			    $html = mapi_openproperty($mapimessage, PR_HTML);
             			} else {
             			    $html = '<html>'.
             				    '<head>'.
             				    '<meta name="Generator" content="Z-Push">'.
             				    '<meta http-equiv="Content-Type" content="text/html; charset=utf-8">'.
             				    '</head>'.
             				    '<body>'.
             				    str_replace("\n","<BR>",str_replace("\r","<BR>", str_replace("\r\n","<BR>",mapi_openproperty($mapimessage, PR_BODY)))).
             				    '</body>'.
             				    '</html>';
             			}
             */
             $html = str_replace("\n", "", str_replace("\r", "", $html));
             $message->airsyncbasebody->estimateddatasize = strlen($html);
             if ($truncsize != false && isset($bodypreference[2]["TruncationSize"]) && strlen($html) > $bodypreference[2]["TruncationSize"]) {
                 $html = utf8_truncate($html, $bodypreference[2]["TruncationSize"]);
                 $message->airsyncbasebody->truncated = 1;
             }
             $message->airsyncbasebody->data = w2u($html);
             debugLog("HTML Body!");
         } else {
             $body = mapi_openproperty($mapimessage, PR_BODY);
             $message->airsyncbasebody->estimateddatasize = strlen($body);
             $message->airsyncbasebody->type = 1;
             if ($truncsize != false && isset($bodypreference[1]["TruncationSize"]) && strlen($body) > $bodypreference[1]["TruncationSize"]) {
                 $body = utf8_truncate($body, $bodypreference[1]["TruncationSize"]);
                 $message->airsyncbasebody->truncated = 1;
             }
             $message->airsyncbasebody->data = str_replace("\n", "\r\n", w2u(str_replace("\r", "", $body)));
             debugLog("Plain Body!");
         }
         if (isset($bodypreference[1]["Preview"])) {
             $body = mapi_openproperty($mapimessage, PR_BODY);
             $body = substr($body, 0, $bodypreference[1]["Preview"]);
             $body = utf8_truncate($body, $bodypreference[1]["Preview"]);
             //		    $message->airsyncbasebody->preview = 1;
             $message->airsyncbasebody->preview = str_replace("\n", "\r\n", w2u(str_replace("\r", "", $body)));
             //			unset($message->airsyncbasebody->data);
         }
         $message->md5body = md5(mapi_openproperty($mapimessage, PR_BODY));
         if (!isset($message->airsyncbasebody->data) || strlen($message->airsyncbasebody->data) == 0) {
             $message->airsyncbasebody->data = " ";
         }
     }
     // END CHANGED dw2412 Support Protocol Version 12 (added bodypreference compare)
     // Override 'From' to show "Full Name <*****@*****.**>"
     // CHANGED dw2412 to honor the Reply-To Information in messages
     //		setlocale(LC_CTYPE,'en_US.utf-8');
     $messageprops = mapi_getprops($mapimessage, array(PR_SENT_REPRESENTING_NAME, PR_SENT_REPRESENTING_ENTRYID, PR_SOURCE_KEY, PR_REPLY_RECIPIENT_ENTRIES, PR_SENDER_NAME, PR_SENDER_ENTRYID, PR_RECEIVED_BY_NAME, PR_DISPLAY_TO, PR_DISPLAY_CC));
     if (isset($messageprops[PR_SOURCE_KEY])) {
         $sourcekey = $messageprops[PR_SOURCE_KEY];
     } else {
         return false;
     }
     $fromname = $fromaddr = "";
     if ($message->messageclass == "IPM.Note.Mobile.SMS") {
         if (isset($messageprops[PR_SENT_REPRESENTING_NAME])) {
             $fromname = $messageprops[PR_SENT_REPRESENTING_NAME];
         }
         if (isset($messageprops[PR_SENT_REPRESENTING_ENTRYID])) {
             $fromaddr = $this->_getMobileAddressFromEntryID($messageprops[PR_SENT_REPRESENTING_ENTRYID]);
         }
         if ($fromname == $fromaddr) {
             $fromname = "";
         }
         if ($fromname) {
             $from = "\"" . w2u($fromname) . "\" [MOBILE:" . w2u($fromaddr) . "]";
         } else {
             $from = "\"" . w2u($fromaddr) . "\" [MOBILE:" . w2u($fromaddr) . "]";
         }
         //changed dw2412 to get rid at HTC Mail (Android) from error message... Not nice but effective...
     } else {
         if (isset($messageprops[PR_SENT_REPRESENTING_NAME])) {
             $fromname = $messageprops[PR_SENT_REPRESENTING_NAME];
         }
         if (isset($messageprops[PR_SENT_REPRESENTING_ENTRYID])) {
             $fromaddr = $this->_getSMTPAddressFromEntryID($messageprops[PR_SENT_REPRESENTING_ENTRYID]);
         }
         if ($fromname == $fromaddr) {
             $fromname = "";
         }
         if ($fromname) {
             $from = "\"" . w2u($fromname) . "\" <" . w2u($fromaddr) . ">";
         } else {
             $from = "\"" . w2u($fromaddr) . "\" <" . w2u($fromaddr) . ">";
         }
         //changed dw2412 to get rid at HTC Mail (Android) from error message... Not nice but effective...
         if (isset($messageprops[PR_SENDER_NAME])) {
             $sendername = $messageprops[PR_SENDER_NAME];
         }
         if (isset($messageprops[PR_SENDER_ENTRYID])) {
             $senderaddr = $this->_getSMTPAddressFromEntryID($messageprops[PR_SENDER_ENTRYID]);
         }
     }
     if (isset($senderaddr) && $fromaddr != $senderaddr) {
         $message->sender = isset($sendername) ? $sendername : $senderaddr;
     }
     $message->from = $from;
     // START DETECTING BCC Received
     if (isset($messageprops[PR_RECEIVED_BY_NAME])) {
         debugLog($messageprops[PR_DISPLAY_TO] . "|" . $messageprops[PR_DISPLAY_CC] . "|" . $messageprops[PR_RECEIVED_BY_NAME]);
         if (strpos($messageprops[PR_DISPLAY_CC], $messageprops[PR_RECEIVED_BY_NAME]) === false && strpos($messageprops[PR_DISPLAY_TO], $messageprops[PR_RECEIVED_BY_NAME]) === false) {
             $message->receivedasbcc = true;
         }
     }
     // START ADDED dw2412 to honor reply to address
     if (isset($messageprops[PR_REPLY_RECIPIENT_ENTRIES])) {
         $replyto = $this->_readReplyRecipientEntry($messageprops[PR_REPLY_RECIPIENT_ENTRIES]);
         foreach ($replyto as $value) {
             $message->reply_to .= $value['email_address'] . ";";
         }
         $message->reply_to = substr($message->reply_to, 0, strlen($message->reply_to) - 1);
     }
     // END ADDED dw2412 to honor reply to address
     // START ADDED dw2412 conversation index
     $messageprops = mapi_getprops($mapimessage, array(PR_CONVERSATION_INDEX));
     if (CONVERSATIONINDEX == true) {
         if (isset($messageprops[PR_CONVERSATION_INDEX]) && strlen($messageprops[PR_CONVERSATION_INDEX]) >= 22) {
             $tmp = $messageprops[PR_CONVERSATION_INDEX];
             $convid = substr($tmp, 6, 16);
             $convindex = substr($tmp, 0, 22);
             $tmp = substr($messageprops[PR_CONVERSATION_INDEX], 22, strlen($messageprops[PR_CONVERSATION_INDEX] - 22));
             while (strlen($tmp) > 0) {
                 $convindex .= substr($tmp, 0, 5);
                 $tmp = substr($tmp, 5, strlen($tmp) - 5);
             }
         } else {
             debugLog("New conversation Index");
             $ci = new ConversationIndex();
             $ci->Create();
             $tmp = $ci->Encode();
             $convid = substr($tmp, 6, 16);
             $convindex = substr($tmp, 0, 22);
         }
         $message->conversationid = $convid;
         $message->conversationindex = $convindex;
     }
     // END ADDED dw2412 conversation index
     // process Meeting Requests
     if (isset($message->messageclass) && strpos($message->messageclass, "IPM.Schedule.Meeting") === 0) {
         $message->meetingrequest = new SyncMeetingRequest();
         $this->_getPropsFromMAPI($message->meetingrequest, $mapimessage, $this->_meetingrequestmapping);
         $goidtag = $this->_getPropIdFromString("PT_BINARY:{6ED8DA90-450B-101B-98DA-00AA003F1305}:0x3");
         $timezonetag = $this->_getPropIDFromString("PT_BINARY:{00062002-0000-0000-C000-000000000046}:0x8233");
         $recReplTime = $this->_getPropIDFromString("PT_SYSTIME:{00062002-0000-0000-C000-000000000046}:0x8228");
         $isrecurringtag = $this->_getPropIDFromString("PT_BOOLEAN:{00062002-0000-0000-C000-000000000046}:0x8223");
         $recurringstate = $this->_getPropIDFromString("PT_BINARY:{00062002-0000-0000-C000-000000000046}:0x8216");
         $appSeqNr = $this->_getPropIDFromString("PT_LONG:{00062002-0000-0000-C000-000000000046}:0x8201");
         $lidIsException = $this->_getPropIDFromString("PT_BOOLEAN:{00062002-0000-0000-C000-000000000046}:0xA");
         $recurStartTime = $this->_getPropIDFromString("PT_LONG:{6ED8DA90-450B-101B-98DA-00AA003F1305}:0xE");
         $props = mapi_getprops($mapimessage, array($goidtag, $timezonetag, $recReplTime, $isrecurringtag, $recurringstate, $appSeqNr, $lidIsException, $recurStartTime));
         // Get the GOID
         if (isset($props[$goidtag])) {
             $message->meetingrequest->globalobjid = base64_encode($props[$goidtag]);
         }
         // Set Timezone
         if (isset($props[$timezonetag])) {
             $tz = $this->_getTZFromMAPIBlob($props[$timezonetag]);
         } else {
             $tz = $this->_getGMTTZ();
         }
         $message->meetingrequest->timezone = base64_encode($this->_getSyncBlobFromTZ($tz));
         // send basedate if exception
         if (isset($props[$recReplTime]) || isset($props[$lidIsException]) && $props[$lidIsException] == true) {
             if (isset($props[$recReplTime])) {
                 $basedate = $props[$recReplTime];
                 $message->meetingrequest->recurrenceid = $this->_getGMTTimeByTZ($basedate, $this->_getGMTTZ());
             } else {
                 if (!isset($props[$goidtag]) || !isset($props[$recurStartTime]) || !isset($props[$timezonetag])) {
                     debugLog("Missing property to set correct basedate for exception");
                 } else {
                     $basedate = extractBaseDate($props[$goidtag], $props[$recurStartTime]);
                     $message->meetingrequest->recurrenceid = $this->_getGMTTimeByTZ($basedate, $tz);
                 }
             }
         }
         // Organizer is the sender
         $message->meetingrequest->organizer = $message->from;
         // Process recurrence
         if (isset($props[$isrecurringtag]) && $props[$isrecurringtag]) {
             $myrec = new SyncMeetingRequestRecurrence();
             // get recurrence -> put $message->meetingrequest as message so the 'alldayevent' is set correctly
             $this->_getRecurrence($mapimessage, $props, $message->meetingrequest, $myrec, $tz);
             $message->meetingrequest->recurrences = array($myrec);
         }
         // Force the 'alldayevent' in the object at all times. (non-existent == 0)
         if (!isset($message->meetingrequest->alldayevent) || $message->meetingrequest->alldayevent == "") {
             $message->meetingrequest->alldayevent = 0;
         }
         // Instancetype
         // 0 = single appointment
         // 1 = master recurring appointment
         // 2 = single instance of recurring appointment
         // 3 = exception of recurring appointment
         $message->meetingrequest->instancetype = 0;
         if (isset($props[$isrecurringtag]) && $props[$isrecurringtag] == 1) {
             $message->meetingrequest->instancetype = 1;
         } else {
             if ((!isset($props[$isrecurringtag]) || $props[$isrecurringtag] == 0) && isset($message->meetingrequest->recurrenceid)) {
                 if (isset($props[$appSeqNr]) && $props[$appSeqNr] == 0) {
                     $message->meetingrequest->instancetype = 2;
                 } else {
                     $message->meetingrequest->instancetype = 3;
                 }
             }
         }
         // Disable reminder if it is off
         $reminderset = $this->_getPropIDFromString("PT_BOOLEAN:{00062008-0000-0000-C000-000000000046}:0x8503");
         $remindertime = $this->_getPropIDFromString("PT_LONG:{00062008-0000-0000-C000-000000000046}:0x8501");
         $messageprops = mapi_getprops($mapimessage, array($reminderset, $remindertime));
         if (!isset($messageprops[$reminderset]) || $messageprops[$reminderset] == false) {
             $message->meetingrequest->reminder = "";
         } else {
             ///set the default reminder time to seconds
             if ($messageprops[$remindertime] == 0x5ae980e1) {
                 $message->meetingrequest->reminder = 900;
             } else {
                 $message->meetingrequest->reminder = $messageprops[$remindertime] * 60;
             }
         }
         // Set sensitivity to 0 if missing
         if (!isset($message->meetingrequest->sensitivity)) {
             $message->meetingrequest->sensitivity = 0;
         }
     }
     // Add attachments
     $attachtable = mapi_message_getattachmenttable($mapimessage);
     // START CHANGED dw2412 to contain the Attach Method (needed for eml discovery)
     $rows = mapi_table_queryallrows($attachtable, array(PR_ATTACH_NUM, PR_ATTACH_METHOD));
     // END CHANGED dw2412 to contain the Attach Method (needed for eml discovery)
     $n = 1;
     foreach ($rows as $row) {
         if (isset($row[PR_ATTACH_NUM])) {
             $mapiattach = mapi_message_openattach($mapimessage, $row[PR_ATTACH_NUM]);
             // CHANGED dw2412 for HTML eMail Inline Attachments...
             $attachprops = mapi_getprops($mapiattach, array(PR_ATTACH_LONG_FILENAME, PR_ATTACH_FILENAME, PR_DISPLAY_NAME, PR_ATTACH_FLAGS, PR_ATTACH_CONTENT_ID, PR_ATTACH_MIME_TAG));
             $attach = new SyncAttachment();
             // START CHANGED dw2412 EML Attachment
             if ($row[PR_ATTACH_METHOD] == ATTACH_EMBEDDED_MSG) {
                 $stream = buildEMLAttachment($mapiattach);
             } else {
                 $stream = mapi_openpropertytostream($mapiattach, PR_ATTACH_DATA_BIN);
             }
             // END CHANGED dw2412 EML Attachment
             if ($stream) {
                 $stat = mapi_stream_stat($stream);
                 if (isset($message->_mapping['POOMMAIL:Attachments'])) {
                     $attach = new SyncAttachment();
                 } else {
                     if (isset($message->_mapping['AirSyncBase:Attachments'])) {
                         $attach = new SyncAirSyncBaseAttachment();
                     }
                 }
                 $attach->attsize = $stat["cb"];
                 $attach->attname = bin2hex($this->_folderid) . ":" . bin2hex($sourcekey) . ":" . $row[PR_ATTACH_NUM];
                 // START CHANGED dw2412 EML Attachment
                 debugLog("Mime Tag for attachment='" . strtolower(trim($attachprops[PR_ATTACH_MIME_TAG])) . "'");
                 if (isset($attachprops[PR_ATTACH_LONG_FILENAME])) {
                     $attach->displayname = w2u($attachprops[PR_ATTACH_LONG_FILENAME]);
                 } else {
                     if (isset($attachprops[PR_ATTACH_FILENAME])) {
                         $attach->displayname = w2u($attachprops[PR_ATTACH_FILENAME]);
                     } else {
                         if (isset($attachprops[PR_DISPLAY_NAME])) {
                             $attach->displayname = w2u($attachprops[PR_DISPLAY_NAME]);
                         } else {
                             if (strtolower(trim($attachprops[PR_ATTACH_MIME_TAG])) == 'multipart/signed') {
                                 $attach->displayname = w2u("smime.p7m");
                             } else {
                                 $attach->displayname = w2u("untitled");
                             }
                         }
                     }
                 }
                 if (strlen($attach->displayname) == 0) {
                     $attach->displayname = "Untitled_" . $n;
                     $n++;
                 }
                 if ($row[PR_ATTACH_METHOD] == ATTACH_EMBEDDED_MSG) {
                     $attach->displayname .= w2u(".eml");
                 }
                 // END CHANGED dw2412 EML Attachment
                 // in case the attachment has got a content id it is an inline one...
                 if (isset($attachprops[PR_ATTACH_CONTENT_ID])) {
                     $attach->isinline = true;
                     $attach->method = 6;
                     $attach->contentid = $attachprops[PR_ATTACH_CONTENT_ID];
                     $attach->contenttype = $attachprops[PR_ATTACH_MIME_TAG];
                     // for inline images the displayname extension must match the content type
                     // otherwise on i.e. windows mobile the image is not being displayed / automatically downloaded
                     switch (strtolower($attachprops[PR_ATTACH_MIME_TAG])) {
                         case 'image/gif':
                             if (substr(strtolower($attach->displayname), strlen($attach->displayname) - 4) != '.gif') {
                                 $attach->displayname .= '.gif';
                             }
                             break;
                         case 'image/jpg':
                         case 'image/jpeg':
                             if (substr(strtolower($attach->displayname), strlen($attach->displayname) - 4) != '.jpg') {
                                 $attach->displayname .= '.jpg';
                             }
                             break;
                         case 'image/png':
                             if (substr(strtolower($attach->displayname), strlen($attach->displayname) - 4) != '.png') {
                                 $attach->displayname .= '.png';
                             }
                             break;
                     }
                 } else {
                     $attach->attmethod = 1;
                 }
                 if (isset($message->_mapping['POOMMAIL:Attachments'])) {
                     if (!isset($message->attachments) || !is_array($message->attachments)) {
                         $message->attachments = array();
                     }
                     array_push($message->attachments, $attach);
                 } else {
                     if (isset($message->_mapping['AirSyncBase:Attachments'])) {
                         if (!isset($message->airsyncbaseattachments) || !is_array($message->airsyncbaseattachments)) {
                             $message->airsyncbaseattachments = array();
                         }
                         array_push($message->airsyncbaseattachments, $attach);
                     }
                 }
             }
         }
     }
     // Get To/Cc as SMTP addresses (this is different from displayto and displaycc because we are putting
     // in the SMTP addresses as well, while displayto and displaycc could just contain the display names
     $to = array();
     $cc = array();
     $reciptable = mapi_message_getrecipienttable($mapimessage);
     $rows = mapi_table_queryallrows($reciptable, array(PR_RECIPIENT_TYPE, PR_DISPLAY_NAME, PR_ADDRTYPE, PR_EMAIL_ADDRESS, PR_SMTP_ADDRESS));
     foreach ($rows as $row) {
         $address = "";
         $fulladdr = "";
         $addrtype = isset($row[PR_ADDRTYPE]) ? $row[PR_ADDRTYPE] : "";
         if (isset($row[PR_SMTP_ADDRESS])) {
             $address = $row[PR_SMTP_ADDRESS];
         } else {
             if ($addrtype == "SMTP" && isset($row[PR_EMAIL_ADDRESS])) {
                 $address = $row[PR_EMAIL_ADDRESS];
             } else {
                 if ($addrtype == "MOBILE" && isset($row[PR_EMAIL_ADDRESS])) {
                     $address = $row[PR_EMAIL_ADDRESS];
                 }
             }
         }
         $name = isset($row[PR_DISPLAY_NAME]) ? $row[PR_DISPLAY_NAME] : "";
         if ($message->messageclass == "IPM.Note.Mobile.SMS") {
             if ($name == "" || $name == $address) {
                 $fulladdr = "\"" . w2u($address) . "\" [MOBILE:" . w2u($address) . "]";
             } else {
                 if (substr($name, 0, 1) != '"' && substr($name, -1) != '"') {
                     $fulladdr = "\"" . w2u($name) . "\" [MOBILE:" . w2u($address) . "]";
                 } else {
                     $fulladdr = w2u($name) . " [MOBILE:" . w2u($address) . "]";
                 }
             }
         } else {
             if ($name == "" || $name == $address) {
                 $fulladdr = w2u($address);
             } else {
                 if (substr($name, 0, 1) != '"' && substr($name, -1) != '"') {
                     $fulladdr = "\"" . w2u($name) . "\" <" . w2u($address) . ">";
                 } else {
                     $fulladdr = w2u($name) . "<" . w2u($address) . ">";
                 }
             }
         }
         if ($row[PR_RECIPIENT_TYPE] == MAPI_TO) {
             array_push($to, $fulladdr);
         } else {
             if ($row[PR_RECIPIENT_TYPE] == MAPI_CC) {
                 array_push($cc, $fulladdr);
             }
         }
     }
     if (defined('LIMIT_RECIPIENTS')) {
         if (count($to) > LIMIT_RECIPIENTS) {
             debugLog("Recipient amount limitted. No to recipients added!");
             $to = array();
             $message->displayto = "";
         }
         if (count($cc) > LIMIT_RECIPIENTS) {
             debugLog("Recipient amount limitted. No cc recipients added!");
             $cc = array();
         }
     }
     $message->to = implode(", ", $to);
     $message->cc = implode(", ", $cc);
     // CHANGED dw2412 to not have this problem at my system with mapi_inetmapi_imtoinet segfault
     if ($mimesupport == 2 && function_exists("mapi_inetmapi_imtoinet") && !isset($message->airsyncbasebody) && (!defined('ICS_IMTOINET_SEGFAULT') || ICS_IMTOINET_SEGFAULT == false)) {
         $addrBook = mapi_openaddressbook($this->_session);
         $mstream = mapi_inetmapi_imtoinet($this->_session, $addrBook, $mapimessage, array());
         $mstreamstat = mapi_stream_stat($mstream);
         if ($mstreamstat['cb'] < MAX_EMBEDDED_SIZE) {
             $message->mimetruncated = 0;
             $mstreamcontent = mapi_stream_read($mstream, MAX_EMBEDDED_SIZE);
             $message->mimedata = $mstreamcontent;
             $message->mimesize = $mstreamstat["cb"];
             unset($message->body, $message->bodytruncated);
         }
     }
     return $message;
 }
Esempio n. 4
0
 function GetMessage($folderid, $id, $truncsize, $mimesupport = 0)
 {
     debugLog("IMAP-GetMessage: (fid: '{$folderid}'  id: '{$id}'  truncsize: {$truncsize})");
     // Get flags, etc
     $stat = $this->StatMessage($folderid, $id);
     if ($stat) {
         $this->imap_reopenFolder($folderid);
         $mail = @imap_fetchheader($this->_mbox, $id, FT_PREFETCHTEXT | FT_UID) . @imap_body($this->_mbox, $id, FT_PEEK | FT_UID);
         $mobj = new Mail_mimeDecode($mail);
         $message = $mobj->decode(array('decode_headers' => true, 'decode_bodies' => true, 'include_bodies' => true, 'input' => $mail, 'crlf' => "\n", 'charset' => 'utf-8'));
         $output = new SyncMail();
         $body = $this->getBody($message);
         // truncate body, if requested
         if (strlen($body) > $truncsize) {
             $body = utf8_truncate($body, $truncsize);
             $output->bodytruncated = 1;
         } else {
             $body = $body;
             $output->bodytruncated = 0;
         }
         $body = str_replace("\n", "\r\n", str_replace("\r", "", $body));
         $output->bodysize = strlen($body);
         $output->body = $body;
         $output->datereceived = isset($message->headers["date"]) ? strtotime($message->headers["date"]) : null;
         $output->displayto = isset($message->headers["to"]) ? $message->headers["to"] : null;
         $output->importance = isset($message->headers["x-priority"]) ? preg_replace("/\\D+/", "", $message->headers["x-priority"]) : null;
         $output->messageclass = "IPM.Note";
         $output->subject = isset($message->headers["subject"]) ? $message->headers["subject"] : "";
         $output->read = $stat["flags"];
         $output->to = isset($message->headers["to"]) ? $message->headers["to"] : null;
         $output->cc = isset($message->headers["cc"]) ? $message->headers["cc"] : null;
         $output->from = isset($message->headers["from"]) ? $message->headers["from"] : null;
         $output->reply_to = isset($message->headers["reply-to"]) ? $message->headers["reply-to"] : null;
         // Attachments are only searched in the top-level part
         $n = 0;
         if (isset($message->parts)) {
             foreach ($message->parts as $part) {
                 if (isset($part->disposition) && ($part->disposition == "attachment" || $part->disposition == "inline")) {
                     $attachment = new SyncAttachment();
                     if (isset($part->body)) {
                         $attachment->attsize = strlen($part->body);
                     }
                     if (isset($part->d_parameters['filename'])) {
                         $attname = $part->d_parameters['filename'];
                     } else {
                         if (isset($part->ctype_parameters['name'])) {
                             $attname = $part->ctype_parameters['name'];
                         } else {
                             if (isset($part->headers['content-description'])) {
                                 $attname = $part->headers['content-description'];
                             } else {
                                 $attname = "unknown attachment";
                             }
                         }
                     }
                     $attachment->displayname = $attname;
                     $attachment->attname = $folderid . ":" . $id . ":" . $n;
                     $attachment->attmethod = 1;
                     $attachment->attoid = isset($part->headers['content-id']) ? $part->headers['content-id'] : "";
                     array_push($output->attachments, $attachment);
                 }
                 $n++;
             }
         }
         // unset mimedecoder & mail
         unset($mobj);
         unset($mail);
         return $output;
     }
     return false;
 }
Esempio n. 5
0
 public function update()
 {
     $this->language->load('checkout/cart');
     $json = array();
     if (isset($this->request->post['product_id'])) {
         $this->load->model('catalog/product');
         $product_info = $this->model_catalog_product->getProduct($this->request->post['product_id']);
         if ($product_info) {
             if (isset($this->request->post['quantity'])) {
                 $quantity = $this->request->post['quantity'];
             } else {
                 $quantity = 1;
             }
             $product_total = 0;
             $products = $this->cart->getProducts();
             foreach ($products as $product_2) {
                 if ($product_2['product_id'] == $this->request->post['product_id']) {
                     $product_total += $product_2['quantity'];
                 }
             }
             if ($product_info['minimum'] > $product_total + $quantity) {
                 $json['error']['warning'] = sprintf($this->language->get('error_minimum'), $product_info['name'], $product_info['minimum']);
             }
             if (isset($this->request->post['option'])) {
                 $option = array_filter($this->request->post['option']);
             } else {
                 $option = array();
             }
             $product_options = $this->model_catalog_product->getProductOptions($this->request->post['product_id']);
             foreach ($product_options as $product_option) {
                 if ($product_option['required'] && (!isset($this->request->post['option'][$product_option['product_option_id']]) || !$this->request->post['option'][$product_option['product_option_id']])) {
                     $json['error'][$product_option['product_option_id']] = sprintf($this->language->get('error_required'), $product_option['name']);
                 }
             }
         }
         if (!isset($json['error'])) {
             $this->cart->add($this->request->post['product_id'], $quantity, $option);
             $json['success'] = sprintf($this->language->get('text_success'), $this->url->link('product/product', 'product_id=' . $this->request->post['product_id']), $product_info['name'], $this->url->link('checkout/cart'));
             unset($this->session->data['shipping_methods']);
             unset($this->session->data['shipping_method']);
             unset($this->session->data['payment_methods']);
             unset($this->session->data['payment_method']);
         } else {
             $json['redirect'] = str_replace('&amp;', '&', $this->url->link('product/product', 'product_id=' . $this->request->post['product_id']));
         }
     }
     if (isset($this->request->post['remove'])) {
         $this->cart->remove($this->request->post['remove']);
         unset($this->session->data['shipping_methods']);
         unset($this->session->data['shipping_method']);
         unset($this->session->data['payment_methods']);
         unset($this->session->data['payment_method']);
     }
     if (isset($this->request->post['voucher'])) {
         if ($this->session->data['vouchers'][$this->request->post['voucher']]) {
             unset($this->session->data['vouchers'][$this->request->post['voucher']]);
         }
     }
     $this->load->model('tool/image');
     $this->data['text_empty'] = $this->language->get('text_empty');
     $this->data['button_checkout'] = $this->language->get('button_checkout');
     $this->data['button_remove'] = $this->language->get('button_remove');
     $this->data['products'] = array();
     foreach ($this->cart->getProducts() as $result) {
         if ($result['image']) {
             $image = $this->model_tool_image->resize($result['image'], 40, 40);
         } else {
             $image = '';
         }
         $option_data = array();
         foreach ($result['option'] as $option) {
             if ($option['type'] != 'file') {
                 $option_data[] = array('name' => $option['name'], 'value' => utf8_truncate($option['option_value']));
             } else {
                 $this->load->library('encryption');
                 $encryption = new Encryption($this->config->get('config_encryption'));
                 $file = substr($encryption->decrypt($option['option_value']), 0, strrpos($encryption->decrypt($option['option_value']), '.'));
                 $option_data[] = array('name' => $option['name'], 'value' => utf8_truncate($file));
             }
         }
         if ($this->config->get('config_customer_price') && $this->customer->isLogged() || !$this->config->get('config_customer_price')) {
             $price = $this->currency->format($this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax')));
         } else {
             $price = false;
         }
         if ($this->config->get('config_customer_price') && $this->customer->isLogged() || !$this->config->get('config_customer_price')) {
             $total = $this->currency->format($this->tax->calculate($result['total'], $result['tax_class_id'], $this->config->get('config_tax')));
         } else {
             $total = false;
         }
         $this->data['products'][] = array('key' => $result['key'], 'product_id' => $result['product_id'], 'thumb' => $image, 'name' => $result['name'], 'model' => $result['model'], 'option' => $option_data, 'quantity' => $result['quantity'], 'stock' => $result['stock'], 'price' => $price, 'total' => $total, 'href' => $this->url->link('product/product', 'product_id=' . $result['product_id']));
     }
     // Gift Voucher
     $this->data['vouchers'] = array();
     if (isset($this->session->data['vouchers']) && $this->session->data['vouchers']) {
         foreach ($this->session->data['vouchers'] as $key => $voucher) {
             $this->data['vouchers'][] = array('key' => $key, 'description' => $voucher['description'], 'amount' => $this->currency->format($voucher['amount']));
         }
     }
     // Calculate Totals
     $total_data = array();
     $total = 0;
     $taxes = $this->cart->getTaxes();
     if ($this->config->get('config_customer_price') && $this->customer->isLogged() || !$this->config->get('config_customer_price')) {
         $this->load->model('setting/extension');
         $sort_order = array();
         $results = $this->model_setting_extension->getExtensions('total');
         foreach ($results as $key => $value) {
             $sort_order[$key] = $this->config->get($value['code'] . '_sort_order');
         }
         array_multisort($sort_order, SORT_ASC, $results);
         foreach ($results as $result) {
             if ($this->config->get($result['code'] . '_status')) {
                 $this->load->model('total/' . $result['code']);
                 $this->{'model_total_' . $result['code']}->getTotal($total_data, $total, $taxes);
             }
         }
         $sort_order = array();
         foreach ($total_data as $key => $value) {
             $sort_order[$key] = $value['sort_order'];
         }
         array_multisort($sort_order, SORT_ASC, $total_data);
     }
     $json['total'] = sprintf($this->language->get('text_items'), $this->cart->countProducts() + (isset($this->session->data['vouchers']) ? count($this->session->data['vouchers']) : 0), $this->currency->format($total));
     $this->data['totals'] = $total_data;
     $this->data['checkout'] = $this->url->link('checkout/checkout', '', 'SSL');
     if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/common/cart.tpl')) {
         $this->template = $this->config->get('config_template') . '/template/common/cart.tpl';
     } else {
         $this->template = 'default/template/common/cart.tpl';
     }
     $json['output'] = $this->render();
     $this->response->setOutput(json_encode($json));
 }
Esempio n. 6
0
 public function index()
 {
     $this->language->load('product/compare');
     $this->load->model('catalog/product');
     $this->load->model('tool/image');
     if (!isset($this->session->data['compare'])) {
         $this->session->data['compare'] = array();
     }
     if (isset($this->request->post['remove'])) {
         $key = array_search($this->request->post['remove'], $this->session->data['compare']);
         if ($key !== false) {
             unset($this->session->data['compare'][$key]);
         }
         $this->redirect($this->url->link('product/compare'));
     }
     $this->document->setTitle($this->language->get('heading_title'));
     $this->data['breadcrumbs'] = array();
     $this->data['breadcrumbs'][] = array('text' => $this->language->get('text_home'), 'href' => $this->url->link('common/home'), 'separator' => false);
     $url = '';
     if (isset($this->request->get['compare'])) {
         $url .= 'compare=' . $this->request->get['compare'];
     }
     $this->data['breadcrumbs'][] = array('text' => $this->language->get('heading_title'), 'href' => $this->url->link('product/compare', $url), 'separator' => $this->language->get('text_separator'));
     $this->data['heading_title'] = $this->language->get('heading_title');
     $this->data['text_product'] = $this->language->get('text_product');
     $this->data['text_name'] = $this->language->get('text_name');
     $this->data['text_image'] = $this->language->get('text_image');
     $this->data['text_price'] = $this->language->get('text_price');
     $this->data['text_model'] = $this->language->get('text_model');
     $this->data['text_manufacturer'] = $this->language->get('text_manufacturer');
     $this->data['text_availability'] = $this->language->get('text_availability');
     $this->data['text_rating'] = $this->language->get('text_rating');
     $this->data['text_summary'] = $this->language->get('text_summary');
     $this->data['text_weight'] = $this->language->get('text_weight');
     $this->data['text_dimension'] = $this->language->get('text_dimension');
     $this->data['text_remove'] = $this->language->get('text_remove');
     $this->data['text_empty'] = $this->language->get('text_empty');
     $this->data['button_cart'] = $this->language->get('button_cart');
     $this->data['button_continue'] = $this->language->get('button_continue');
     $this->data['action'] = $this->url->link('product/compare');
     $this->data['products'] = array();
     $this->data['attribute_groups'] = array();
     foreach ($this->session->data['compare'] as $product_id) {
         $product_info = $this->model_catalog_product->getProduct($product_id);
         if ($product_info) {
             if ($product_info['image']) {
                 $image = $this->model_tool_image->resize($product_info['image'], $this->config->get('config_image_compare_width'), $this->config->get('config_image_compare_height'));
             } else {
                 $image = false;
             }
             if ($this->config->get('config_customer_price') && $this->customer->isLogged() || !$this->config->get('config_customer_price')) {
                 $price = $this->currency->format($this->tax->calculate($product_info['price'], $product_info['tax_class_id'], $this->config->get('config_tax')));
             } else {
                 $price = false;
             }
             if ((double) $product_info['special']) {
                 $special = $this->currency->format($this->tax->calculate($product_info['special'], $product_info['tax_class_id'], $this->config->get('config_tax')));
             } else {
                 $special = false;
             }
             if ($product_info['quantity'] <= 0) {
                 $availability = $product_info['stock_status'];
             } elseif ($this->config->get('config_stock_display')) {
                 $availability = $product_info['quantity'];
             } else {
                 $availability = $this->language->get('text_instock');
             }
             $attribute_data = array();
             $attribute_groups = $this->model_catalog_product->getProductAttributes($product_id);
             foreach ($attribute_groups as $attribute_group) {
                 foreach ($attribute_group['attribute'] as $attribute) {
                     $attribute_data[$attribute['attribute_id']] = $attribute['text'];
                 }
             }
             $this->data['products'][$product_id] = array('product_id' => $product_info['product_id'], 'name' => $product_info['name'], 'thumb' => $image, 'price' => $price, 'special' => $special, 'description' => utf8_truncate(strip_tags(html_entity_decode($product_info['description'], ENT_QUOTES, 'UTF-8')), 400, '&nbsp;&hellip;', true), 'model' => $product_info['model'], 'manufacturer' => $product_info['manufacturer'], 'availability' => $availability, 'rating' => (int) $product_info['rating'], 'reviews' => sprintf($this->language->get('text_reviews'), (int) $product_info['reviews']), 'weight' => $this->weight->format($product_info['weight'], $product_info['weight_class_id']), 'length' => $this->length->format($product_info['length'], $product_info['length_class_id']), 'width' => $this->length->format($product_info['width'], $product_info['length_class_id']), 'height' => $this->length->format($product_info['height'], $product_info['length_class_id']), 'attribute' => $attribute_data, 'href' => $this->url->link('product/product', 'product_id=' . $product_id), 'remove' => $this->url->link('product/product', 'product_id=' . $product_id));
             foreach ($attribute_groups as $attribute_group) {
                 $this->data['attribute_groups'][$attribute_group['attribute_group_id']]['name'] = $attribute_group['name'];
                 foreach ($attribute_group['attribute'] as $attribute) {
                     $this->data['attribute_groups'][$attribute_group['attribute_group_id']]['attribute'][$attribute['attribute_id']]['name'] = $attribute['name'];
                 }
             }
         }
     }
     $this->data['continue'] = $this->url->link('common/home');
     if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/product/compare.tpl')) {
         $this->template = $this->config->get('config_template') . '/template/product/compare.tpl';
     } else {
         $this->template = 'default/template/product/compare.tpl';
     }
     $this->children = array('common/column_left', 'common/column_right', 'common/content_top', 'common/content_bottom', 'common/footer', 'common/header');
     $this->response->setOutput($this->render());
 }
Esempio n. 7
0
 /**
  * Convert note to requested bodypreference format and truncate if requested
  *
  * @param $note string containing the plaintext message
  * @param $bodypreference object
  * @param &$airsyncbasebody the airsyncbasebody object to send to the client
  *
  * @return string plain textbody for message or false
  */
 public function note2messagenote($note, $bodypreference, &$airsyncbasebody)
 {
     //error_log (__METHOD__);
     if ($bodypreference == false) {
         return $note;
     } else {
         if (isset($bodypreference[2])) {
             debugLog("HTML Body");
             $airsyncbasebody->type = 2;
             $html = '<html>' . '<head>' . '<meta name="Generator" content="eGroupware/Z-Push">' . '<meta http-equiv="Content-Type" content="text/html; charset=utf-8">' . '</head>' . '<body>' . str_replace(array("\n", "\r", "\r\n"), "<br />", $note) . '</body>' . '</html>';
             if (isset($bodypreference[2]["TruncationSize"]) && strlen($html) > $bodypreference[2]["TruncationSize"]) {
                 $html = utf8_truncate($html, $bodypreference[2]["TruncationSize"]);
                 $airsyncbasebody->truncated = 1;
             }
             $airsyncbasebody->estimateddatasize = strlen($html);
             $airsyncbasebody->data = $html;
         } else {
             debugLog("Plaintext Body");
             $airsyncbasebody->type = 1;
             $plainnote = str_replace("\n", "\r\n", str_replace("\r", "", $note));
             if (isset($bodypreference[1]["TruncationSize"]) && strlen($plainnote) > $bodypreference[1]["TruncationSize"]) {
                 $plainnote = utf8_truncate($plainnote, $bodypreference[1]["TruncationSize"]);
                 $airsyncbasebody->truncated = 1;
             }
             $airsyncbasebody->estimateddatasize = strlen($plainnote);
             $airsyncbasebody->data = $plainnote;
         }
         if ($airsyncbasebody->type != 3 && (!isset($airsyncbasebody->data) || strlen($airsyncbasebody->data) == 0)) {
             $airsyncbasebody->data = " ";
         }
     }
 }
Esempio n. 8
0
 public function index()
 {
     if (!$this->cart->hasProducts() && (!isset($this->session->data['vouchers']) || !$this->session->data['vouchers']) || !$this->cart->hasStock() && !$this->config->get('config_stock_checkout')) {
         $json['redirect'] = $this->url->link('checkout/cart');
     }
     $this->load->model('account/address');
     if ($this->customer->isLogged()) {
         $payment_address = $this->model_account_address->getAddress($this->session->data['payment_address_id']);
     } elseif (isset($this->session->data['guest'])) {
         $payment_address = $this->session->data['guest']['payment'];
     }
     if (!isset($payment_address)) {
         $json['redirect'] = $this->url->link('checkout/checkout', '', 'SSL');
     }
     if (!isset($this->session->data['payment_method'])) {
         $json['redirect'] = $this->url->link('checkout/checkout', '', 'SSL');
     }
     if ($this->cart->hasShipping()) {
         $this->load->model('account/address');
         if ($this->customer->isLogged()) {
             $shipping_address = $this->model_account_address->getAddress($this->session->data['shipping_address_id']);
         } elseif (isset($this->session->data['guest'])) {
             $shipping_address = $this->session->data['guest']['shipping'];
         }
         if (!isset($shipping_address)) {
             $json['redirect'] = $this->url->link('checkout/checkout', '', 'SSL');
         }
         if (!isset($this->session->data['shipping_method'])) {
             $json['redirect'] = $this->url->link('checkout/checkout', '', 'SSL');
         }
     } else {
         unset($this->session->data['guest']['shipping']);
         unset($this->session->data['shipping_address_id']);
         unset($this->session->data['shipping_method']);
         unset($this->session->data['shipping_methods']);
     }
     $json = array();
     if (!$json) {
         $total_data = array();
         $total = 0;
         $taxes = $this->cart->getTaxes();
         $this->load->model('setting/extension');
         $sort_order = array();
         $results = $this->model_setting_extension->getExtensions('total');
         foreach ($results as $key => $value) {
             $sort_order[$key] = $this->config->get($value['code'] . '_sort_order');
         }
         array_multisort($sort_order, SORT_ASC, $results);
         foreach ($results as $result) {
             if ($this->config->get($result['code'] . '_status')) {
                 $this->load->model('total/' . $result['code']);
                 $this->{'model_total_' . $result['code']}->getTotal($total_data, $total, $taxes);
             }
         }
         $sort_order = array();
         foreach ($total_data as $key => $value) {
             $sort_order[$key] = $value['sort_order'];
         }
         array_multisort($sort_order, SORT_ASC, $total_data);
         $this->language->load('checkout/checkout');
         $data = array();
         $data['invoice_prefix'] = $this->config->get('config_invoice_prefix');
         $data['store_id'] = $this->config->get('config_store_id');
         $data['store_name'] = $this->config->get('config_name');
         if ($data['store_id']) {
             $data['store_url'] = $this->config->get('config_url');
         } else {
             $data['store_url'] = HTTP_SERVER;
         }
         if ($this->customer->isLogged()) {
             $data['customer_id'] = $this->customer->getId();
             $data['customer_group_id'] = $this->customer->getCustomerGroupId();
             $data['firstname'] = $this->customer->getFirstName();
             $data['lastname'] = $this->customer->getLastName();
             $data['email'] = $this->customer->getEmail();
             $data['telephone'] = $this->customer->getTelephone();
             $data['fax'] = $this->customer->getFax();
             $this->load->model('account/address');
             $payment_address = $this->model_account_address->getAddress($this->session->data['payment_address_id']);
         } elseif (isset($this->session->data['guest'])) {
             $data['customer_id'] = 0;
             $data['customer_group_id'] = $this->config->get('config_customer_group_id');
             $data['firstname'] = $this->session->data['guest']['firstname'];
             $data['lastname'] = $this->session->data['guest']['lastname'];
             $data['email'] = $this->session->data['guest']['email'];
             $data['telephone'] = $this->session->data['guest']['telephone'];
             $data['fax'] = $this->session->data['guest']['fax'];
             $payment_address = $this->session->data['guest']['payment'];
         }
         $data['payment_firstname'] = $payment_address['firstname'];
         $data['payment_lastname'] = $payment_address['lastname'];
         $data['payment_company'] = $payment_address['company'];
         $data['payment_address_1'] = $payment_address['address_1'];
         $data['payment_address_2'] = $payment_address['address_2'];
         $data['payment_city'] = $payment_address['city'];
         $data['payment_postcode'] = $payment_address['postcode'];
         $data['payment_zone'] = $payment_address['zone'];
         $data['payment_zone_id'] = $payment_address['zone_id'];
         $data['payment_country'] = $payment_address['country'];
         $data['payment_country_id'] = $payment_address['country_id'];
         $data['payment_address_format'] = $payment_address['address_format'];
         if (isset($this->session->data['payment_method']['title'])) {
             $data['payment_method'] = $this->session->data['payment_method']['title'];
         } else {
             $data['payment_method'] = '';
         }
         if ($this->cart->hasShipping()) {
             if ($this->customer->isLogged()) {
                 $this->load->model('account/address');
                 $shipping_address = $this->model_account_address->getAddress($this->session->data['shipping_address_id']);
             } elseif (isset($this->session->data['guest'])) {
                 $shipping_address = $this->session->data['guest']['shipping'];
             }
             $data['shipping_firstname'] = $shipping_address['firstname'];
             $data['shipping_lastname'] = $shipping_address['lastname'];
             $data['shipping_company'] = $shipping_address['company'];
             $data['shipping_address_1'] = $shipping_address['address_1'];
             $data['shipping_address_2'] = $shipping_address['address_2'];
             $data['shipping_city'] = $shipping_address['city'];
             $data['shipping_postcode'] = $shipping_address['postcode'];
             $data['shipping_zone'] = $shipping_address['zone'];
             $data['shipping_zone_id'] = $shipping_address['zone_id'];
             $data['shipping_country'] = $shipping_address['country'];
             $data['shipping_country_id'] = $shipping_address['country_id'];
             $data['shipping_address_format'] = $shipping_address['address_format'];
             if (isset($this->session->data['shipping_method']['title'])) {
                 $data['shipping_method'] = $this->session->data['shipping_method']['title'];
             } else {
                 $data['shipping_method'] = '';
             }
         } else {
             $data['shipping_firstname'] = '';
             $data['shipping_lastname'] = '';
             $data['shipping_company'] = '';
             $data['shipping_address_1'] = '';
             $data['shipping_address_2'] = '';
             $data['shipping_city'] = '';
             $data['shipping_postcode'] = '';
             $data['shipping_zone'] = '';
             $data['shipping_zone_id'] = '';
             $data['shipping_country'] = '';
             $data['shipping_country_id'] = '';
             $data['shipping_address_format'] = '';
             $data['shipping_method'] = '';
         }
         $this->load->library('encryption');
         $product_data = array();
         foreach ($this->cart->getProducts() as $product) {
             $option_data = array();
             foreach ($product['option'] as $option) {
                 if ($option['type'] != 'file') {
                     $option_data[] = array('product_option_id' => $option['product_option_id'], 'product_option_value_id' => $option['product_option_value_id'], 'product_option_id' => $option['product_option_id'], 'product_option_value_id' => $option['product_option_value_id'], 'option_id' => $option['option_id'], 'option_value_id' => $option['option_value_id'], 'name' => $option['name'], 'value' => $option['option_value'], 'type' => $option['type']);
                 } else {
                     $encryption = new Encryption($this->config->get('config_encryption'));
                     $option_data[] = array('product_option_id' => $option['product_option_id'], 'product_option_value_id' => $option['product_option_value_id'], 'product_option_id' => $option['product_option_id'], 'product_option_value_id' => $option['product_option_value_id'], 'option_id' => $option['option_id'], 'option_value_id' => $option['option_value_id'], 'name' => $option['name'], 'value' => $encryption->decrypt($option['option_value']), 'type' => $option['type']);
                 }
             }
             $product_data[] = array('product_id' => $product['product_id'], 'name' => $product['name'], 'model' => $product['model'], 'option' => $option_data, 'download' => $product['download'], 'quantity' => $product['quantity'], 'subtract' => $product['subtract'], 'price' => $product['price'], 'total' => $product['total'], 'tax' => $this->tax->getTax($product['total'], $product['tax_class_id']));
         }
         // Gift Voucher
         if (isset($this->session->data['vouchers']) && $this->session->data['vouchers']) {
             foreach ($this->session->data['vouchers'] as $voucher) {
                 $product_data[] = array('product_id' => 0, 'name' => $voucher['description'], 'model' => '', 'option' => array(), 'download' => array(), 'quantity' => 1, 'subtract' => false, 'price' => $voucher['amount'], 'total' => $voucher['amount'], 'tax' => 0);
             }
         }
         $data['products'] = $product_data;
         $data['totals'] = $total_data;
         $data['comment'] = $this->session->data['comment'];
         $data['total'] = $total;
         $data['reward'] = $this->cart->getTotalRewardPoints();
         if (isset($this->request->cookie['tracking'])) {
             $this->load->model('affiliate/affiliate');
             $affiliate_info = $this->model_affiliate_affiliate->getAffiliateByCode($this->request->cookie['tracking']);
             if ($affiliate_info) {
                 $data['affiliate_id'] = $affiliate_info['affiliate_id'];
                 $data['commission'] = $total / 100 * $affiliate_info['commission'];
             } else {
                 $data['affiliate_id'] = 0;
                 $data['commission'] = 0;
             }
         } else {
             $data['affiliate_id'] = 0;
             $data['commission'] = 0;
         }
         $data['language_id'] = $this->config->get('config_language_id');
         $data['currency_id'] = $this->currency->getId();
         $data['currency_code'] = $this->currency->getCode();
         $data['currency_value'] = $this->currency->getValue($this->currency->getCode());
         $data['ip'] = $this->request->server['REMOTE_ADDR'];
         $this->load->model('checkout/order');
         $this->session->data['order_id'] = $this->model_checkout_order->create($data);
         // Gift Voucher
         if (isset($this->session->data['vouchers']) && is_array($this->session->data['vouchers'])) {
             $this->load->model('checkout/voucher');
             foreach ($this->session->data['vouchers'] as $voucher) {
                 $this->model_checkout_voucher->addVoucher($this->session->data['order_id'], $voucher);
             }
         }
         $this->data['column_name'] = $this->language->get('column_name');
         $this->data['column_model'] = $this->language->get('column_model');
         $this->data['column_quantity'] = $this->language->get('column_quantity');
         $this->data['column_price'] = $this->language->get('column_price');
         $this->data['column_total'] = $this->language->get('column_total');
         $this->data['products'] = array();
         foreach ($this->cart->getProducts() as $product) {
             $option_data = array();
             foreach ($product['option'] as $option) {
                 if ($option['type'] != 'file') {
                     $option_data[] = array('name' => $option['name'], 'value' => utf8_truncate($option['option_value']));
                 } else {
                     $this->load->library('encryption');
                     $encryption = new Encryption($this->config->get('config_encryption'));
                     $file = substr($encryption->decrypt($option['option_value']), 0, strrpos($encryption->decrypt($option['option_value']), '.'));
                     $option_data[] = array('name' => $option['name'], 'value' => utf8_truncate($file));
                 }
             }
             $this->data['products'][] = array('product_id' => $product['product_id'], 'name' => $product['name'], 'model' => $product['model'], 'option' => $option_data, 'quantity' => $product['quantity'], 'subtract' => $product['subtract'], 'tax' => $this->tax->getTax($product['total'], $product['tax_class_id']), 'price' => $this->currency->format($product['price']), 'total' => $this->currency->format($product['total']), 'href' => $this->url->link('product/product', 'product_id=' . $product['product_id']));
         }
         // Gift Voucher
         $this->data['vouchers'] = array();
         if (isset($this->session->data['vouchers']) && $this->session->data['vouchers']) {
             foreach ($this->session->data['vouchers'] as $key => $voucher) {
                 $this->data['vouchers'][] = array('description' => $voucher['description'], 'amount' => $this->currency->format($voucher['amount']));
             }
         }
         $this->data['totals'] = $total_data;
         $this->data['payment'] = $this->getChild('payment/' . $this->session->data['payment_method']['code']);
         if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/checkout/confirm.tpl')) {
             $this->template = $this->config->get('config_template') . '/template/checkout/confirm.tpl';
         } else {
             $this->template = 'default/template/checkout/confirm.tpl';
         }
         $json['output'] = $this->render();
     }
     $this->response->setOutput(json_encode($json));
 }
Esempio n. 9
0
 function GetMessage($folderid, $id, $truncsize, $bodypreference = false, $optionbodypreference = false, $mimesupport = 0)
 {
     debugLog("IMAP-GetMessage: (fid: '" . $this->_folders[$folderid] . "'  id: '" . $id . "'  truncsize: {$truncsize})");
     // Get flags, etc
     $stat = $this->StatMessage($folderid, $id);
     if ($stat) {
         $this->imap_reopenFolder($folderid);
         if (defined("IMAP_USE_FETCHHEADER") && IMAP_USE_FETCHHEADER === false) {
             $mail = @imap_fetchbody($this->_mbox, $id, "", FT_UID | FT_PEEK);
         } else {
             $mail = @imap_fetchheader($this->_mbox, $id, FT_UID) . @imap_body($this->_mbox, $id, FT_PEEK | FT_UID);
         }
         // Return in case any errors occured...
         $errors = imap_errors();
         if (is_array($errors)) {
             foreach ($errors as $e) {
                 debugLog("IMAP-errors: {$e}");
                 $fields = explode(':', $e);
                 switch (strtolower(trim($fields[0]))) {
                     case 'security problem':
                         // don't care about security problems!
                         break;
                     default:
                         return false;
                 }
             }
         }
         $mobj = new Mail_mimeDecode($mail);
         $message = $mobj->decode(array('decode_headers' => true, 'decode_bodies' => true, 'rfc_822bodies' => true, 'include_bodies' => true, 'input' => $mail, 'crlf' => "\n", 'charset' => BACKEND_CHARSET));
         $output = new SyncMail();
         // start AS12 Stuff (bodypreference === false) case = old behaviour
         if ($bodypreference === false) {
             $body = $this->getBody($message);
             $body = str_replace("\n", "\r\n", str_replace("\r", "", $body));
             // truncate body, if requested
             if (strlen($body) > $truncsize) {
                 $body = utf8_truncate($body, $truncsize);
                 $output->bodytruncated = 1;
             } else {
                 $body = $body;
                 $output->bodytruncated = 0;
             }
             $output->bodysize = strlen($body);
             $output->body = $body;
         } else {
             if (isset($bodypreference[1]) && !isset($bodypreference[1]["TruncationSize"])) {
                 $bodypreference[1]["TruncationSize"] = 1024 * 1024;
             }
             if (isset($bodypreference[2]) && !isset($bodypreference[2]["TruncationSize"])) {
                 $bodypreference[2]["TruncationSize"] = 1024 * 1024;
             }
             if (isset($bodypreference[3]) && !isset($bodypreference[3]["TruncationSize"])) {
                 $bodypreference[3]["TruncationSize"] = 1024 * 1024;
             }
             if (isset($bodypreference[4]) && !isset($bodypreference[4]["TruncationSize"])) {
                 $bodypreference[4]["TruncationSize"] = 1024 * 1024;
             }
             $output->airsyncbasebody = new SyncAirSyncBaseBody();
             debugLog("airsyncbasebody!");
             $body = "";
             $this->getBodyRecursive($message, "html", $body);
             if ($body != "") {
                 $output->airsyncbasenativebodytype = 2;
             } else {
                 $output->airsyncbasenativebodytype = 1;
                 $this->getBodyRecursive($message, "plain", $body);
             }
             $body = str_replace("\n", "\r\n", str_replace("\r", "", $body));
             if (isset($bodypreference[4]) && ($mimesupport == 2 || $mimesupport == 1 && strtolower($message->ctype_secondary) == 'signed')) {
                 debugLog("MIME Body");
                 $output->airsyncbasebody->type = 4;
                 $rawmessage = $mobj->decode(array('decode_headers' => false, 'decode_bodies' => true, 'rfc_822bodies' => true, 'include_bodies' => true, 'input' => $mail, 'crlf' => "\n", 'charset' => BACKEND_CHARSET));
                 $body = "";
                 foreach ($rawmessage->headers as $key => $value) {
                     if ($key != "content-type" && $key != "mime-version" && $key != "content-transfer-encoding" && !is_array($value)) {
                         $body .= $key . ":";
                         // Split -> Explode replace
                         $tokens = explode(" ", trim($value));
                         $line = "";
                         foreach ($tokens as $valu) {
                             if (strlen($line) + strlen($valu) + 2 > 60) {
                                 $line .= "\n";
                                 $body .= $line;
                                 $line = " " . $valu;
                             } else {
                                 $line .= " " . $valu;
                             }
                         }
                         $body .= $line . "\n";
                     }
                 }
                 unset($rawmessage);
                 $mimemsg = new Mail_mime(array('head_encoding' => 'quoted-printable', 'text_encoding' => 'quoted-printable', 'html_encoding' => 'base64', 'head_charset' => 'utf-8', 'text_charset' => 'utf-8', 'html_charset' => 'utf-8', 'eol' => "\n", 'delay_file_io' => false));
                 $this->getAllAttachmentsRecursive($message, $mimemsg);
                 if ($output->airsyncbasenativebodytype == 1) {
                     $this->getBodyRecursive($message, "plain", $plain);
                     $this->getBodyRecursive($message, "html", $html);
                     if ($html == "") {
                         $this->getBodyRecursive($message, "plain", $html);
                     }
                     if ($html == "" && $plain == "" && strlen($mobj->_body) != "") {
                         $body .= "Content-Type:" . $message->headers['content-type'] . "\r\n";
                         $body .= "Content-Transfer-Encoding:" . $message->headers['content-transfer-encoding'] . "\r\n";
                         $body .= "\n\n" . $mobj->_body;
                         $output->airsyncbasebody->data = $body;
                     }
                     $mimemsg->setTXTBody(str_replace("\n", "\r\n", str_replace("\r", "", w2u($plain))));
                     $html = '<html>' . '<head>' . '<meta name="Generator" content="Z-Push">' . '<meta http-equiv="Content-Type" content="text/html; charset=utf-8">' . '</head>' . '<body>' . str_replace("\n", "<BR>", str_replace("\r", "", str_replace("\r\n", "<BR>", w2u($html)))) . '</body>' . '</html>';
                     $mimemsg->setHTMLBody(str_replace("\n", "\r\n", str_replace("\r", "", $html)));
                 }
                 if ($output->airsyncbasenativebodytype == 2) {
                     $this->getBodyRecursive($message, "plain", $plain);
                     if ($plain == "") {
                         $this->getBodyRecursive($message, "html", $plain);
                         // remove css-style tags
                         $plain = preg_replace("/<style.*?<\\/style>/is", "", $plain);
                         // remove all other html
                         $plain = preg_replace("/<br.*>/is", "<br>", $plain);
                         $plain = preg_replace("/<br >/is", "<br>", $plain);
                         $plain = preg_replace("/<br\\/>/is", "<br>", $plain);
                         $plain = str_replace("<br>", "\r\n", $plain);
                         $plain = strip_tags($plain);
                     }
                     $mimemsg->setTXTBody(str_replace("\n", "\r\n", str_replace("\r", "", w2u($plain))));
                     $this->getBodyRecursive($message, "html", $html);
                     $mimemsg->setHTMLBody(str_replace("\n", "\r\n", str_replace("\r", "", w2u($html))));
                 }
                 if (!isset($output->airsyncbasebody->data)) {
                     $output->airsyncbasebody->data = $body . $mimemsg->txtheaders() . "\n\n" . $mimemsg->get();
                 }
                 $output->airsyncbasebody->estimateddatasize = byte_strlen($output->airsyncbasebody->data);
             } else {
                 if (isset($bodypreference[2])) {
                     debugLog("HTML Body");
                     // Send HTML if requested and native type was html
                     $output->airsyncbasebody->type = 2;
                     $this->getBodyRecursive($message, "plain", $plain);
                     $this->getBodyRecursive($message, "html", $html);
                     if ($html == "") {
                         $this->getBodyRecursive($message, "plain", $html);
                     }
                     if ($html == "" && $plain == "" && byte_strlen($mobj->_body) > 0) {
                         $plain = $html = $mobj->_quotedPrintableDecode($mobj->_body);
                     }
                     if ($output->airsyncbasenativebodytype == 2) {
                         $html = w2u($html);
                     } else {
                         $html = '<html>' . '<head>' . '<meta name="Generator" content="Z-Push">' . '<meta http-equiv="Content-Type" content="text/html; charset=utf-8">' . '</head>' . '<body>' . str_replace("\n", "<BR>", str_replace("\r", "<BR>", str_replace("\r\n", "<BR>", w2u($plain)))) . '</body>' . '</html>';
                     }
                     if (isset($bodypreference[2]["TruncationSize"]) && strlen($html) > $bodypreference[2]["TruncationSize"]) {
                         $html = utf8_truncate($html, $bodypreference[2]["TruncationSize"]);
                         $output->airsyncbasebody->truncated = 1;
                     }
                     $output->airsyncbasebody->data = $html;
                     $output->airsyncbasebody->estimateddatasize = byte_strlen($html);
                 } else {
                     // Send Plaintext as Fallback or if original body is plaintext
                     debugLog("Plaintext Body");
                     $plain = $this->getBody($message);
                     $plain = w2u(str_replace("\n", "\r\n", str_replace("\r", "", $plain)));
                     $output->airsyncbasebody->type = 1;
                     if (isset($bodypreference[1]["TruncationSize"]) && strlen($plain) > $bodypreference[1]["TruncationSize"]) {
                         $plain = utf8_truncate($plain, $bodypreference[1]["TruncationSize"]);
                         $output->airsyncbasebody->truncated = 1;
                     }
                     $output->airsyncbasebody->estimateddatasize = byte_strlen($plain);
                     $output->airsyncbasebody->data = $plain;
                 }
             }
             // In case we have nothing for the body, send at least a blank...
             // dw2412 but only in case the body is not rtf!
             if ($output->airsyncbasebody->type != 3 && (!isset($output->airsyncbasebody->data) || byte_strlen($output->airsyncbasebody->data) == 0)) {
                 $output->airsyncbasebody->data = " ";
             }
         }
         // end AS12 Stuff
         // small dirty correction for (i.e. Tobit David) since it has the opinion the UTC Timezone abbreviation is UT :-(
         $output->datereceived = isset($message->headers["date"]) ? strtotime($message->headers["date"] . (substr($message->headers["date"], -3) == " UT" ? "C" : "")) : null;
         $output->importance = isset($message->headers["x-priority"]) ? preg_replace("/\\D+/", "", $message->headers["x-priority"]) : null;
         $output->messageclass = "IPM.Note";
         if (strtolower($message->ctype_primary) == "multipart") {
             switch (strtolower($message->ctype_secondary)) {
                 case 'signed':
                     $output->messageclass = "IPM.Note.SMIME.MultipartSigned";
                     break;
                 default:
                     $output->messageclass = "IPM.Note";
             }
         }
         $output->subject = isset($message->headers["subject"]) ? trim(w2u($message->headers["subject"])) : "";
         $output->read = $stat["flags"];
         if (isset($message->headers["to"]) && (preg_match('/^\\"{0,1}(.+[^ ^\\"]){0,1}\\"{0,1}[ ]{0,1}<(.*)>$/', $message->headers["to"], $addrparts) || preg_match('/^(.*@.*)$/', $message->headers["to"], $addrparts))) {
             $output->to = trim(w2u('"' . ($addrparts[1] != "" || $addrparts[2] == "" ? $addrparts[1] : $addrparts[2]) . '" <' . (!isset($addrparts[2]) || $addrparts[2] == "" ? $addrparts[1] : $addrparts[2]) . '>'));
             $output->displayto = trim(w2u($addrparts[1] != "" ? $addrparts[1] : $addrparts[2]));
             unset($addrparts);
         } else {
             $output->to = trim(w2u('"Unknown@localhost" <Unknown@localhost>'));
         }
         if (isset($message->headers["from"]) && (preg_match('/^\\"{0,1}(.+[^ ^\\"]){0,1}\\"{0,1}[ ]{0,1}<(.*)>$/', $message->headers["from"], $addrparts) || preg_match('/^(.*@.*)$/', $message->headers["from"], $addrparts))) {
             $output->from = trim(w2u('"' . ($addrparts[1] != "" || $addrparts[2] == "" ? $addrparts[1] : $addrparts[2]) . '" <' . (!isset($addrparts[2]) || $addrparts[2] == "" ? $addrparts[1] : $addrparts[2]) . '>'));
             unset($addrparts);
         } else {
             $output->from = trim(w2u('"Unknown@localhost" <Unknown@localhost>'));
         }
         $output->cc = isset($message->headers["cc"]) ? trim(w2u($message->headers["cc"])) : null;
         $output->reply_to = isset($message->headers["reply-to"]) ? trim(w2u($message->headers["reply-to"])) : null;
         // start AS12 Stuff
         $output->poommailflag = new SyncPoommailFlag();
         $output->poommailflag->flagstatus = 0;
         $output->internetcpid = 65001;
         $output->contentclass = "urn:content-classes:message";
         // end AS12 Stuff
         // Attachments are only searched in the top-level part
         if (isset($message->parts)) {
             $this->getAttachmentDetailsRecursive($message, $output, $folderid, $id);
         }
         // unset mimedecoder & mail
         unset($mobj);
         unset($mail);
         return $output;
     }
     return false;
 }
Esempio n. 10
0
 public function info()
 {
     if (isset($this->request->get['order_id'])) {
         $order_id = $this->request->get['order_id'];
     } else {
         $order_id = 0;
     }
     if (!$this->customer->isLogged()) {
         $this->session->data['redirect'] = $this->url->link('account/order/info', 'order_id=' . $order_id, 'SSL');
         $this->redirect($this->url->link('account/login', '', 'SSL'));
     }
     $this->language->load('account/order');
     $this->load->model('account/order');
     $order_info = $this->model_account_order->getOrder($order_id);
     if ($order_info) {
         if ($this->request->server['REQUEST_METHOD'] == 'POST' && $this->validate()) {
             if ($this->request->post['action'] == 'reorder') {
                 $order_products = $this->model_account_order->getOrderProducts($order_id);
                 foreach ($order_products as $order_product) {
                     if (in_array($order_product['order_product_id'], $this->request->post['selected'])) {
                         $option_data = array();
                         $order_options = $this->model_account_order->getOrderOptions($order_id, $order_product['order_product_id']);
                         foreach ($order_options as $order_option) {
                             if ($order_option['type'] == 'select' || $order_option['type'] == 'radio') {
                                 $option_data[$order_option['product_option_id']] = $order_option['product_option_value_id'];
                             } elseif ($order_option['type'] == 'checkbox') {
                                 $option_data[$order_option['product_option_id']][] = $order_option['product_option_value_id'];
                             } elseif ($order_option['type'] == 'input' || $order_option['type'] == 'textarea' || $order_option['type'] == 'file' || $order_option['type'] == 'date' || $order_option['type'] == 'datetime' || $order_option['type'] == 'time') {
                                 $option_data[$order_option['product_option_id']] = $order_option['value'];
                             }
                         }
                         $this->cart->add($order_product['product_id'], $order_product['quantity'], $option_data);
                     }
                 }
                 $this->redirect($this->url->link('checkout/cart', '', 'SSL'));
             }
             if ($this->request->post['action'] == 'return') {
                 $order_product_data = array();
                 $order_products = $this->model_account_order->getOrderProducts($order_id);
                 foreach ($order_products as $order_product) {
                     if (in_array($order_product['order_product_id'], $this->request->post['selected'])) {
                         $order_product_data[] = array('name' => $order_product['name'], 'model' => $order_product['model']);
                     }
                 }
                 $this->session->data['return'] = array('order_id' => $order_info['order_id'], 'date_added' => $order_info['date_added'], 'product' => $order_product_data);
                 $this->redirect($this->url->link('account/return/insert', '', 'SSL'));
             }
         }
         $this->document->setTitle($this->language->get('text_order'));
         $this->data['breadcrumbs'] = array();
         $this->data['breadcrumbs'][] = array('text' => $this->language->get('text_home'), 'href' => $this->url->link('common/home'), 'separator' => false);
         $this->data['breadcrumbs'][] = array('text' => $this->language->get('text_account'), 'href' => $this->url->link('account/account', '', 'SSL'), 'separator' => $this->language->get('text_separator'));
         $url = '';
         if (isset($this->request->get['page'])) {
             $url .= '&page=' . $this->request->get['page'];
         }
         $this->data['breadcrumbs'][] = array('text' => $this->language->get('heading_title'), 'href' => $this->url->link('account/order', $url, 'SSL'), 'separator' => $this->language->get('text_separator'));
         $this->data['breadcrumbs'][] = array('text' => $this->language->get('text_order'), 'href' => $this->url->link('account/order/info', 'order_id=' . $this->request->get['order_id'] . $url, 'SSL'), 'separator' => $this->language->get('text_separator'));
         $this->data['heading_title'] = $this->language->get('text_order');
         $this->data['text_order_detail'] = $this->language->get('text_order_detail');
         $this->data['text_invoice_no'] = $this->language->get('text_invoice_no');
         $this->data['text_order_id'] = $this->language->get('text_order_id');
         $this->data['text_date_added'] = $this->language->get('text_date_added');
         $this->data['text_shipping_method'] = $this->language->get('text_shipping_method');
         $this->data['text_shipping_address'] = $this->language->get('text_shipping_address');
         $this->data['text_payment_method'] = $this->language->get('text_payment_method');
         $this->data['text_payment_address'] = $this->language->get('text_payment_address');
         $this->data['text_history'] = $this->language->get('text_history');
         $this->data['text_comment'] = $this->language->get('text_comment');
         $this->data['text_action'] = $this->language->get('text_action');
         $this->data['text_selected'] = $this->language->get('text_selected');
         $this->data['text_reorder'] = $this->language->get('text_reorder');
         $this->data['text_return'] = $this->language->get('text_return');
         $this->data['column_name'] = $this->language->get('column_name');
         $this->data['column_model'] = $this->language->get('column_model');
         $this->data['column_quantity'] = $this->language->get('column_quantity');
         $this->data['column_price'] = $this->language->get('column_price');
         $this->data['column_total'] = $this->language->get('column_total');
         $this->data['column_date_added'] = $this->language->get('column_date_added');
         $this->data['column_status'] = $this->language->get('column_status');
         $this->data['column_comment'] = $this->language->get('column_comment');
         $this->data['button_continue'] = $this->language->get('button_continue');
         if (isset($this->error['warning'])) {
             $this->data['error_warning'] = $this->error['warning'];
         } else {
             $this->data['error_warning'] = '';
         }
         $this->data['action'] = $this->url->link('account/order/info', 'order_id=' . $this->request->get['order_id'], 'SSL');
         if ($order_info['invoice_no']) {
             $this->data['invoice_no'] = $order_info['invoice_prefix'] . $order_info['invoice_no'];
         } else {
             $this->data['invoice_no'] = '';
         }
         $this->data['order_id'] = $this->request->get['order_id'];
         $this->data['date_added'] = date($this->language->get('date_format_short'), strtotime($order_info['date_added']));
         if ($order_info['shipping_address_format']) {
             $format = $order_info['shipping_address_format'];
         } else {
             $format = '{firstname} {lastname}' . "\n" . '{company}' . "\n" . '{address_1}' . "\n" . '{address_2}' . "\n" . '{city} {postcode}' . "\n" . '{zone}' . "\n" . '{country}';
         }
         $find = array('{firstname}', '{lastname}', '{company}', '{address_1}', '{address_2}', '{city}', '{postcode}', '{zone}', '{zone_code}', '{country}');
         $replace = array('firstname' => $order_info['shipping_firstname'], 'lastname' => $order_info['shipping_lastname'], 'company' => $order_info['shipping_company'], 'address_1' => $order_info['shipping_address_1'], 'address_2' => $order_info['shipping_address_2'], 'city' => $order_info['shipping_city'], 'postcode' => $order_info['shipping_postcode'], 'zone' => $order_info['shipping_zone'], 'zone_code' => $order_info['shipping_zone_code'], 'country' => $order_info['shipping_country']);
         $this->data['shipping_address'] = str_replace(array("\r\n", "\r", "\n"), '<br />', preg_replace(array("/\\s\\s+/", "/\r\r+/", "/\n\n+/"), '<br />', trim(str_replace($find, $replace, $format))));
         $this->data['shipping_method'] = $order_info['shipping_method'];
         if ($order_info['payment_address_format']) {
             $format = $order_info['payment_address_format'];
         } else {
             $format = '{firstname} {lastname}' . "\n" . '{company}' . "\n" . '{address_1}' . "\n" . '{address_2}' . "\n" . '{city} {postcode}' . "\n" . '{zone}' . "\n" . '{country}';
         }
         $find = array('{firstname}', '{lastname}', '{company}', '{address_1}', '{address_2}', '{city}', '{postcode}', '{zone}', '{zone_code}', '{country}');
         $replace = array('firstname' => $order_info['payment_firstname'], 'lastname' => $order_info['payment_lastname'], 'company' => $order_info['payment_company'], 'address_1' => $order_info['payment_address_1'], 'address_2' => $order_info['payment_address_2'], 'city' => $order_info['payment_city'], 'postcode' => $order_info['payment_postcode'], 'zone' => $order_info['payment_zone'], 'zone_code' => $order_info['payment_zone_code'], 'country' => $order_info['payment_country']);
         $this->data['payment_address'] = str_replace(array("\r\n", "\r", "\n"), '<br />', preg_replace(array("/\\s\\s+/", "/\r\r+/", "/\n\n+/"), '<br />', trim(str_replace($find, $replace, $format))));
         $this->data['payment_method'] = $order_info['payment_method'];
         $this->data['products'] = array();
         $products = $this->model_account_order->getOrderProducts($this->request->get['order_id']);
         foreach ($products as $product) {
             $option_data = array();
             $options = $this->model_account_order->getOrderOptions($this->request->get['order_id'], $product['order_product_id']);
             foreach ($options as $option) {
                 if ($option['type'] != 'file') {
                     $option_data[] = array('name' => $option['name'], 'value' => utf8_truncate($option['value']));
                 } else {
                     $filename = substr($option['value'], 0, strrpos($option['value'], '.'));
                     $option_data[] = array('name' => $option['name'], 'value' => utf8_truncate($filename));
                 }
             }
             $this->data['products'][] = array('order_product_id' => $product['order_product_id'], 'name' => $product['name'], 'model' => $product['model'], 'option' => $option_data, 'quantity' => $product['quantity'], 'price' => $this->currency->format($product['price'], $order_info['currency_code'], $order_info['currency_value']), 'total' => $this->currency->format($product['total'], $order_info['currency_code'], $order_info['currency_value']), 'selected' => isset($this->request->post['selected']) && in_array($result['order_product_id'], $this->request->post['selected']));
         }
         $this->data['totals'] = $this->model_account_order->getOrderTotals($this->request->get['order_id']);
         $this->data['comment'] = $order_info['comment'];
         $this->data['histories'] = array();
         $results = $this->model_account_order->getOrderHistories($this->request->get['order_id']);
         foreach ($results as $result) {
             $this->data['histories'][] = array('date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])), 'status' => $result['status'], 'comment' => nl2br($result['comment']));
         }
         $this->data['continue'] = $this->url->link('account/order', '', 'SSL');
         if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/account/order_info.tpl')) {
             $this->template = $this->config->get('config_template') . '/template/account/order_info.tpl';
         } else {
             $this->template = 'default/template/account/order_info.tpl';
         }
         $this->children = array('common/column_left', 'common/column_right', 'common/content_top', 'common/content_bottom', 'common/footer', 'common/header');
         $this->response->setOutput($this->render());
     } else {
         $this->document->setTitle($this->language->get('text_order'));
         $this->data['heading_title'] = $this->language->get('text_order');
         $this->data['text_error'] = $this->language->get('text_error');
         $this->data['button_continue'] = $this->language->get('button_continue');
         $this->data['breadcrumbs'] = array();
         $this->data['breadcrumbs'][] = array('text' => $this->language->get('text_home'), 'href' => $this->url->link('common/home'), 'separator' => false);
         $this->data['breadcrumbs'][] = array('text' => $this->language->get('text_account'), 'href' => $this->url->link('account/account', '', 'SSL'), 'separator' => $this->language->get('text_separator'));
         $this->data['breadcrumbs'][] = array('text' => $this->language->get('heading_title'), 'href' => $this->url->link('account/order', '', 'SSL'), 'separator' => $this->language->get('text_separator'));
         $this->data['breadcrumbs'][] = array('text' => $this->language->get('text_order'), 'href' => $this->url->link('account/order/info', 'order_id=' . $order_id, 'SSL'), 'separator' => $this->language->get('text_separator'));
         $this->data['continue'] = $this->url->link('account/order', '', 'SSL');
         if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/error/not_found.tpl')) {
             $this->template = $this->config->get('config_template') . '/template/error/not_found.tpl';
         } else {
             $this->template = 'default/template/error/not_found.tpl';
         }
         $this->children = array('common/column_left', 'common/column_right', 'common/content_top', 'common/content_bottom', 'common/footer', 'common/header');
         $this->response->setOutput($this->render());
     }
 }
Esempio n. 11
0
 public function info()
 {
     if (isset($this->session->data['note'])) {
         $this->data['note'] = $this->session->data['note'];
         unset($this->session->data['note']);
     } else {
         $this->data['note'] = '';
     }
     $this->modelToolImage = $this->load->model('tool/image');
     if (isset($this->request->get['order_id'])) {
         $order_id = $this->request->get['order_id'];
     } else {
         $order_id = 0;
     }
     if (!$this->customer->isLogged()) {
         $this->session->data['redirect'] = $this->url->link('account/order/info', 'order_id=' . $order_id, 'SSL');
         $this->redirect($this->url->link('account/login', '', 'SSL'));
     }
     $this->language->load('account/order');
     $this->load->model('account/order');
     $order_info = $this->model_account_order->getOrder($order_id);
     if ($order_info) {
         $orderItems = OrderItemDAO::getInstance()->getOrderItems(array('filterOrderId' => $order_id), null, true);
         if ($this->request->server['REQUEST_METHOD'] == 'POST' && $this->validate()) {
             if ($this->request->post['action'] == 'reorder') {
                 foreach ($orderItems as $orderItem) {
                     if (in_array($orderItem->getId(), $this->request->post['selected'])) {
                         $option_data = array();
                         $order_options = $this->model_account_order->getOrderOptions($order_id, $orderItem->getId());
                         foreach ($order_options as $order_option) {
                             if ($order_option['type'] == 'select' || $order_option['type'] == 'radio') {
                                 $option_data[$order_option['product_option_id']] = $order_option['product_option_value_id'];
                             } elseif ($order_option['type'] == 'checkbox') {
                                 $option_data[$order_option['product_option_id']][] = $order_option['product_option_value_id'];
                             } elseif ($order_option['type'] == 'input' || $order_option['type'] == 'textarea' || $order_option['type'] == 'file' || $order_option['type'] == 'date' || $order_option['type'] == 'datetime' || $order_option['type'] == 'time') {
                                 $option_data[$order_option['product_option_id']] = $order_option['value'];
                             }
                         }
                         $this->cart->add($orderItem->getProductId(), $orderItem->getQuantity(), $option_data);
                     }
                 }
                 $this->redirect($this->url->link('checkout/cart', '', 'SSL'));
             }
         }
         $this->setBreadcrumbs();
         $url = '';
         if (isset($this->request->get['page'])) {
             $url .= '&page=' . $this->request->get['page'];
         }
         $this->data['text_order_detail'] = $this->language->get('text_order_detail');
         $this->data['text_invoice_no'] = $this->language->get('text_invoice_no');
         $this->data['text_order_id'] = $this->language->get('text_order_id');
         $this->data['text_date_added'] = $this->language->get('text_date_added');
         $this->data['text_shipping_method'] = $this->language->get('text_shipping_method');
         $this->data['text_shipping_address'] = $this->language->get('text_shipping_address');
         $this->data['text_payment_method'] = $this->language->get('text_payment_method');
         $this->data['text_payment_address'] = $this->language->get('text_payment_address');
         $this->data['text_history'] = $this->language->get('text_history');
         $this->data['text_comment'] = $this->language->get('text_comment');
         $this->data['text_action'] = $this->language->get('text_action');
         $this->data['text_selected'] = $this->language->get('text_selected');
         $this->data['text_reorder'] = $this->language->get('text_reorder');
         $this->data['text_return'] = $this->language->get('text_return');
         $this->data['textAction'] = $this->language->get('ACTION');
         $this->data['textComment'] = $this->language->get('COMMENT');
         $this->data['textOrderItemId'] = $this->language->get('ORDER_ITEM_ID');
         $this->data['textOrderItemImage'] = $this->language->get('IMAGE');
         $this->data['column_name'] = $this->language->get('column_name');
         $this->data['column_model'] = $this->language->get('column_model');
         $this->data['column_quantity'] = $this->language->get('column_quantity');
         $this->data['column_price'] = $this->language->get('column_price');
         $this->data['column_total'] = $this->language->get('column_total');
         $this->data['column_date_added'] = $this->language->get('column_date_added');
         $this->data['column_status'] = $this->language->get('column_status');
         $this->data['button_continue'] = $this->language->get('button_continue');
         $this->data['button_invoice'] = $this->language->get('button_invoice');
         if (isset($this->error['warning'])) {
             $this->data['error_warning'] = $this->error['warning'];
         } else {
             $this->data['error_warning'] = '';
         }
         $this->data['action'] = $this->url->link('account/order/info', 'order_id=' . $this->request->get['order_id'], 'SSL');
         if ($order_info['invoice_no']) {
             $this->data['invoice_no'] = $order_info['invoice_prefix'] . $order_info['invoice_no'];
         } else {
             $this->data['invoice_no'] = '';
         }
         $this->data['order_id'] = $this->request->get['order_id'];
         $this->data['date_added'] = date($this->language->get('date_format_short'), strtotime($order_info['date_added']));
         if ($order_info['shipping_address_format']) {
             $format = $order_info['shipping_address_format'];
         } else {
             $format = '{firstname} {lastname}' . "\n" . '{company}' . "\n" . '{address_1}' . "\n" . '{address_2}' . "\n" . '{city} {postcode}' . "\n" . '{zone}' . "\n" . '{country}';
         }
         $find = array('{firstname}', '{lastname}', '{company}', '{address_1}', '{address_2}', '{city}', '{postcode}', '{zone}', '{zone_code}', '{country}');
         $replace = array('firstname' => $order_info['shipping_firstname'], 'lastname' => $order_info['shipping_lastname'], 'company' => $order_info['shipping_company'], 'address_1' => $order_info['shipping_address_1'], 'address_2' => $order_info['shipping_address_2'], 'city' => $order_info['shipping_city'], 'postcode' => $order_info['shipping_postcode'], 'zone' => $order_info['shipping_zone'], 'zone_code' => $order_info['shipping_zone_code'], 'country' => $order_info['shipping_country']);
         $this->data['shipping_address'] = str_replace(array("\r\n", "\r", "\n"), '<br />', preg_replace(array("/\\s\\s+/", "/\r\r+/", "/\n\n+/"), '<br />', trim(str_replace($find, $replace, $format))));
         $this->data['shipping_method'] = ShippingMethodDAO::getInstance()->getMethod(explode('.', $order_info['shipping_method'])[0])->getName();
         if ($order_info['payment_address_format']) {
             $format = $order_info['payment_address_format'];
         } else {
             $format = '{firstname} {lastname}' . "\n" . '{company}' . "\n" . '{address_1}' . "\n" . '{address_2}' . "\n" . '{city} {postcode}' . "\n" . '{zone}' . "\n" . '{country}';
         }
         $find = array('{firstname}', '{lastname}', '{company}', '{address_1}', '{address_2}', '{city}', '{postcode}', '{zone}', '{zone_code}', '{country}');
         $replace = array('firstname' => $order_info['payment_firstname'], 'lastname' => $order_info['payment_lastname'], 'company' => $order_info['payment_company'], 'address_1' => $order_info['payment_address_1'], 'address_2' => $order_info['payment_address_2'], 'city' => $order_info['payment_city'], 'postcode' => $order_info['payment_postcode'], 'zone' => $order_info['payment_zone'], 'zone_code' => $order_info['payment_zone_code'], 'country' => $order_info['payment_country']);
         $this->data['payment_address'] = str_replace(array("\r\n", "\r", "\n"), '<br />', preg_replace(array("/\\s\\s+/", "/\r\r+/", "/\n\n+/"), '<br />', trim(str_replace($find, $replace, $format))));
         $this->data['payment_method'] = $order_info['payment_method'];
         // ----- deposit modules START -----
         $this->data['text_payment_method'] = '';
         $this->load->model('account/multi_pay');
         $this->data['payment_method'] = $this->model_account_multi_pay->order_info($order_info);
         // ----- deposit modules END -----
         $this->data['products'] = array();
         //			$orderItems = OrderItemDAO::getInstance()->getOrderItems(
         //                array('filterOrderId' => $this->request->get['order_id']), null, true
         //            );
         //            $products = $this->model_account_order->getOrderProducts($this->request->get['order_id']);
         foreach ($orderItems as $orderItem) {
             $actions = array();
             if (($orderItem->getStatusId() & 0xffff) <= 2) {
                 $actions[] = array('text' => $this->language->get('CANCEL'), 'href' => $this->url->link('account/orderItems/cancel', 'orderItemId=' . $orderItem->getId() . '&returnUrl=' . urlencode($this->selfUrl)));
             }
             $option_data = array();
             $options = OrderItemDAO::getInstance()->getOptions($orderItem->getId());
             foreach ($options as $option) {
                 if ($option['type'] != 'file') {
                     $option_data[] = array('name' => $option['name'], 'value' => utf8_truncate($option['value']));
                 } else {
                     $filename = substr($option['value'], 0, strrpos($option['value'], '.'));
                     $option_data[] = array('name' => $option['name'], 'value' => utf8_truncate($filename));
                 }
             }
             $product_image = ProductDAO::getInstance()->getImage($orderItem->getProductId());
             if ($orderItem->getImagePath() == '' || $orderItem->getImagePath() == "data/event/agent-moomidae.jpg") {
                 $options = OrderItemDAO::getInstance()->getOptions($orderItem->getId());
                 $itemUrl = !empty($options[REPURCHASE_ORDER_IMAGE_URL_OPTION_ID]['value']) ? $options[REPURCHASE_ORDER_IMAGE_URL_OPTION_ID]['value'] : '';
                 $orderItem->setImagePath(!empty($itemUrl) ? $itemUrl : $orderItem->getImagePath());
             }
             if ($orderItem->getImagePath() && file_exists(DIR_IMAGE . $orderItem->getImagePath())) {
                 $image = $this->modelToolImage->resize($orderItem->getImagePath(), 100, 100);
             } else {
                 $image = $this->modelToolImage->resize($product_image, 100, 100);
             }
             $this->data['products'][] = array('order_product_id' => $orderItem->getId(), 'actions' => $actions, 'comment' => $orderItem->getPublicComment(), 'name' => $orderItem->getName(), 'model' => $orderItem->getModel(), 'option' => $option_data, 'quantity' => $orderItem->getModel(), 'price' => $this->getCurrency()->format($orderItem->getPrice(true), $order_info['currency_code'], 1), 'total' => $this->getCurrency()->format($orderItem->getTotal(true), $order_info['currency_code'], 1), 'imagePath' => $image, 'item_status' => Status::getStatus($orderItem->getStatusId(), $this->config->get('language_id'), true), 'selected' => false);
         }
         $this->data['totals'] = $this->model_account_order->getOrderTotals($this->request->get['order_id']);
         $this->data['comment'] = $order_info['comment'];
         $this->data['histories'] = array();
         $results = $this->model_account_order->getOrderHistories($this->request->get['order_id']);
         foreach ($results as $result) {
             $this->data['histories'][] = array('date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])), 'status' => $result['status'], 'comment' => nl2br($result['comment']));
         }
         $this->data['continue'] = $this->url->link('account/order', '', 'SSL');
         if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/account/order_info.tpl.php')) {
             $this->template = $this->config->get('config_template') . '/template/account/order_info.tpl.php';
         } else {
             $this->template = 'default/template/account/order_info.tpl.php';
         }
         $this->children = array('common/column_left', 'common/column_right', 'common/content_top', 'common/content_bottom', 'common/footer', 'common/header');
         $this->getResponse()->setOutput($this->render());
     } else {
         $this->document->setTitle($this->language->get('text_order'));
         $this->data['heading_title'] = $this->language->get('text_order');
         $this->data['text_error'] = $this->language->get('text_error');
         $this->data['button_continue'] = $this->language->get('button_continue');
         $this->setBreadcrumbs();
         $this->data['continue'] = $this->url->link('account/order', '', 'SSL');
         if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/error/not_found.tpl')) {
             $this->template = $this->config->get('config_template') . '/template/error/not_found.tpl';
         } else {
             $this->template = 'default/template/error/not_found.tpl';
         }
         $this->children = array('common/column_left', 'common/column_right', 'common/content_top', 'common/content_bottom', 'common/footer', 'common/header');
         $this->getResponse()->setOutput($this->render());
     }
 }
Esempio n. 12
0
 public function index()
 {
     //        $this->log->write(print_r($this->request, true));
     $this->getLanguage()->load('product/search');
     if (isset($this->request->get['filter_name'])) {
         $filter_name = $this->request->get['filter_name'];
     } else {
         $filter_name = '';
     }
     //
     //		if (isset($this->request->get['filter_description'])) {
     //			$filter_description = $this->request->get['filter_description'];
     //		} else {
     //			$filter_description = '';
     //		}
     if (isset($this->request->get['filter_category_id'])) {
         $filter_category_id = $this->request->get['filter_category_id'];
     } else {
         $filter_category_id = 0;
     }
     if (isset($this->request->get['filter_sub_category'])) {
         $filter_sub_category = $this->request->get['filter_sub_category'];
     } else {
         $filter_sub_category = '';
     }
     if (isset($this->request->get['sort'])) {
         $sort = $this->request->get['sort'];
     } else {
         $sort = null;
     }
     if (isset($this->request->get['order'])) {
         $order = $this->request->get['order'];
     } else {
         $order = 'ASC';
     }
     if (isset($this->request->get['page'])) {
         $page = $this->request->get['page'];
     } else {
         $page = 1;
     }
     if (isset($this->request->get['limit'])) {
         $limit = $this->request->get['limit'];
     } else {
         $limit = $this->getConfig()->get('config_catalog_limit');
     }
     if (isset($this->request->get['keyword'])) {
         $this->document->setTitle($this->getLanguage()->get('heading_title') . ' - ' . $this->request->get['keyword']);
     } else {
         $this->document->setTitle($this->getLanguage()->get('heading_title'));
     }
     $url = '';
     if (isset($this->request->get['filter_name'])) {
         $url .= '&filter_name=' . $this->request->get['filter_name'];
     }
     if (isset($this->request->get['filter_tag'])) {
         $url .= '&filter_tag=' . $this->request->get['filter_tag'];
     }
     if (isset($this->request->get['filter_description'])) {
         $url .= '&filter_description=' . $this->request->get['filter_description'];
     }
     if (isset($this->request->get['filter_category_id'])) {
         $url .= '&filter_category_id=' . $this->request->get['filter_category_id'];
     }
     if (isset($this->request->get['filter_sub_category'])) {
         $url .= '&filter_sub_category=' . $this->request->get['filter_sub_category'];
     }
     if (isset($this->request->get['sort'])) {
         $url .= '&sort=' . $this->request->get['sort'];
     }
     if (isset($this->request->get['order'])) {
         $url .= '&order=' . $this->request->get['order'];
     }
     if (isset($this->request->get['page'])) {
         $url .= '&page=' . $this->request->get['page'];
     }
     if (isset($this->request->get['limit'])) {
         $url .= '&limit=' . $this->request->get['limit'];
     }
     $this->data['text_compare'] = sprintf($this->getLanguage()->get('text_compare'), isset($this->session->data['compare']) ? count($this->session->data['compare']) : 0);
     $this->data['compare'] = $this->getUrl()->link('product/compare');
     // 3 Level Category Search
     $this->data['categories'] = array();
     $categories_1 = CategoryDAO::getInstance()->getCategoriesByParentId(0);
     foreach ($categories_1 as $category_1) {
         $level_2_data = array();
         $categories_2 = CategoryDAO::getInstance()->getCategoriesByParentId($category_1->getId());
         foreach ($categories_2 as $category_2) {
             $level_3_data = array();
             $categories_3 = CategoryDAO::getInstance()->getCategoriesByParentId($category_2->getId());
             foreach ($categories_3 as $category_3) {
                 $level_3_data[] = array('category_id' => $category_3->getId(), 'name' => $category_3->getDescription()->getName());
             }
             $level_2_data[] = array('category_id' => $category_2->getId(), 'name' => $category_2->getDescription()->getName(), 'children' => $level_3_data);
         }
         $this->data['categories'][] = array('category_id' => $category_1->getId(), 'name' => $category_1->getDescription()->getName(), 'children' => $level_2_data);
     }
     #kabantejay synonymizer start
     $result['description'] = null;
     /// Expression below makes no sense as it refers to non-initialized variable
     //        $result['description'] = preg_replace_callback(
     //            '/\{  (.*?)  \}/xs',
     //            function ($m) {
     //                $ar = explode("|", $m[1]);
     //                return $ar[array_rand($ar, 1)];
     //            },
     //            $result['description']
     //        );
     #kabantejay synonymizer end
     $this->data['products'] = array();
     if (isset($this->request->get['filter_name']) || isset($this->request->get['filter_tag'])) {
         $filter = new FilterTree(['filterEnabled' => true, 'filterCategoryId' => $filter_category_id, 'filterSubCategories' => $filter_sub_category], 'AND', new FilterTree(['filterName' => $filter_name], 'OR', new FilterTree(['filterModel' => $filter_name], 'OR', new FilterTree(['filterTag' => $filter_name]))), true);
         $data = array('filterEnabled' => true, 'filterName' => $filter_name, 'filterCategoryId' => $filter_category_id, 'filterSubCategories' => $filter_sub_category, 'sort' => $sort, 'order' => $order, 'start' => ($page - 1) * $limit, 'limit' => $limit);
         $product_total = ProductDAO::getInstance()->getProductsCount($filter);
         $results = ProductDAO::getInstance()->getProducts($filter, $sort, $order, ($page - 1) * $limit, $limit);
         if ($sort == null) {
             $results = $this->sortByRelevance($results, $filter_name);
         }
         foreach ($results as $product) {
             if ($product->getImagePath()) {
                 $image = ImageService::getInstance()->resize($product->getImagePath(), $this->getConfig()->get('config_image_product_width'), $this->getConfig()->get('config_image_product_height'));
             } else {
                 $image = false;
             }
             if ($this->getConfig()->get('config_customer_price') && $this->customer->isLogged() || !$this->getConfig()->get('config_customer_price')) {
                 $price = $this->getCurrency()->format($product->getPrice());
             } else {
                 $price = false;
             }
             if ((double) $product->getSpecialPrice($this->getCurrentCustomer()->getCustomerGroupId())) {
                 $special = $this->getCurrency()->format($product->getSpecialPrice($this->getCurrentCustomer()->getCustomerGroupId()));
             } else {
                 $special = false;
             }
             //
             //                if ($this->getConfig()->get('config_review_status')) {
             //					$rating = (int)$product->getRating();
             //				} else {
             //					$rating = false;
             //				}
             $this->data['products'][] = array('product_id' => $product->getId(), 'thumb' => $image, 'name' => $product->getName(), 'description' => !is_null($product->getDescriptions()->getDescription($this->getLanguage()->getId())) ? utf8_truncate(strip_tags(html_entity_decode($product->getDescriptions()->getDescription($this->getLanguage()->getId())->getDescription(), ENT_QUOTES, 'UTF-8')), 400, '&nbsp;&hellip;', true) : '', 'price' => $price, 'special' => $special, 'rating' => $product->getRating(), 'reviews' => sprintf($this->getLanguage()->get('text_reviews'), (int) $product->getReviewsCount()), 'href' => $this->getUrl()->link('product/product', $url . '&product_id=' . $product->getId()));
         }
         $url = '';
         if (isset($this->request->get['filter_name'])) {
             $url .= '&filter_name=' . $this->request->get['filter_name'];
         }
         if (isset($this->request->get['filter_tag'])) {
             $url .= '&filter_tag=' . $this->request->get['filter_tag'];
         }
         if (isset($this->request->get['filter_description'])) {
             $url .= '&filter_description=' . $this->request->get['filter_description'];
         }
         if (isset($this->request->get['filter_category_id'])) {
             $url .= '&filter_category_id=' . $this->request->get['filter_category_id'];
         }
         if (isset($this->request->get['filter_sub_category'])) {
             $url .= '&filter_sub_category=' . $this->request->get['filter_sub_category'];
         }
         $this->data['sorts'] = array();
         //			$this->data['sorts'][] = array(
         //				'text'  => $this->getLanguage()->get('text_default'),
         //				'value' => 'p.sort_order-ASC',
         //				'href'  => $this->getUrl()->link('product/search', 'sort=p.sort_order&order=ASC' . $url)
         //			);
         $this->data['sorts'][] = array('text' => $this->getLanguage()->get('RELEVANCE'), 'value' => null, 'href' => $this->getUrl()->link('product/search', '' . $url));
         $this->data['sorts'][] = array('text' => $this->getLanguage()->get('text_name_asc'), 'value' => 'pd.name-ASC', 'href' => $this->getUrl()->link('product/search', 'sort=pd.name&order=ASC' . $url));
         $this->data['sorts'][] = array('text' => $this->getLanguage()->get('text_name_desc'), 'value' => 'pd.name-DESC', 'href' => $this->getUrl()->link('product/search', 'sort=pd.name&order=DESC' . $url));
         $this->data['sorts'][] = array('text' => $this->getLanguage()->get('text_price_asc'), 'value' => 'p.price-ASC', 'href' => $this->getUrl()->link('product/search', 'sort=p.price&order=ASC' . $url));
         $this->data['sorts'][] = array('text' => $this->getLanguage()->get('text_price_desc'), 'value' => 'p.price-DESC', 'href' => $this->getUrl()->link('product/search', 'sort=p.price&order=DESC' . $url));
         $this->data['sorts'][] = array('text' => $this->getLanguage()->get('text_rating_desc'), 'value' => 'rating-DESC', 'href' => $this->getUrl()->link('product/search', 'sort=rating&order=DESC' . $url));
         $this->data['sorts'][] = array('text' => $this->getLanguage()->get('text_rating_asc'), 'value' => 'rating-ASC', 'href' => $this->getUrl()->link('product/search', 'sort=rating&order=ASC' . $url));
         $this->data['sorts'][] = array('text' => $this->getLanguage()->get('text_model_asc'), 'value' => 'p.model-ASC', 'href' => $this->getUrl()->link('product/search', 'sort=p.model&order=ASC' . $url));
         $this->data['sorts'][] = array('text' => $this->getLanguage()->get('text_model_desc'), 'value' => 'p.model-DESC', 'href' => $this->getUrl()->link('product/search', 'sort=p.model&order=DESC' . $url));
         $this->data['limits'] = array();
         $this->data['limits'][] = array('text' => $this->getConfig()->get('config_catalog_limit'), 'value' => $this->getConfig()->get('config_catalog_limit'), 'href' => $this->getUrl()->link('product/search', $url . '&limit=' . $this->getConfig()->get('config_catalog_limit')));
         $this->data['limits'][] = array('text' => 25, 'value' => 25, 'href' => $this->getUrl()->link('product/search', $url . '&limit=25'));
         $this->data['limits'][] = array('text' => 50, 'value' => 50, 'href' => $this->getUrl()->link('product/search', $url . '&limit=50'));
         $this->data['limits'][] = array('text' => 75, 'value' => 75, 'href' => $this->getUrl()->link('product/search', $url . '&limit=75'));
         $this->data['limits'][] = array('text' => 100, 'value' => 100, 'href' => $this->getUrl()->link('product/search', $url . '&limit=100'));
         $pagination = new Pagination();
         $pagination->total = $product_total;
         $pagination->page = $page;
         $pagination->limit = $limit;
         $pagination->text = $this->getLanguage()->get('text_pagination');
         $pagination->url = $this->getUrl()->link('product/search', $url . '&page={page}');
         $this->data['pagination'] = $pagination->render();
     }
     $this->data['filter_name'] = $filter_name;
     //		$this->data['filter_description'] = $filter_description;
     $this->data['filter_category_id'] = $filter_category_id;
     $this->data['filter_sub_category'] = $filter_sub_category;
     $this->data['sort'] = $sort;
     $this->data['order'] = $order;
     $this->data['limit'] = $limit;
     $this->setBreadcrumbs();
     $this->children = array('common/column_left', 'common/column_right', 'common/content_top', 'common/content_bottom', 'common/footer', 'common/header');
     $templateFile = '/template/product/search.tpl.php';
     $templateDir = file_exists(DIR_TEMPLATE . $this->getConfig()->get('config_template') . $templateFile) ? $this->getConfig()->get('config_template') : ($templateDir = 'default');
     $this->getResponse()->setOutput($this->render($templateDir . $templateFile));
 }
Esempio n. 13
0
 public function index()
 {
     $this->language->load('product/special');
     if (isset($this->request->get['sort'])) {
         $sort = $this->request->get['sort'];
     } else {
         $sort = 'p.sort_order';
     }
     if (isset($this->request->get['order'])) {
         $order = $this->request->get['order'];
     } else {
         $order = 'ASC';
     }
     if (isset($this->request->get['page'])) {
         $page = $this->request->get['page'];
     } else {
         $page = 1;
     }
     if (isset($this->request->get['limit'])) {
         $limit = $this->request->get['limit'];
     } else {
         $limit = $this->getConfig()->get('config_catalog_limit');
     }
     $this->document->setTitle($this->language->get('heading_title'));
     $url = '';
     if (isset($this->request->get['sort'])) {
         $url .= '&sort=' . $this->request->get['sort'];
     }
     if (isset($this->request->get['order'])) {
         $url .= '&order=' . $this->request->get['order'];
     }
     if (isset($this->request->get['page'])) {
         $url .= '&page=' . $this->request->get['page'];
     }
     if (isset($this->request->get['limit'])) {
         $url .= '&limit=' . $this->request->get['limit'];
     }
     $this->data['heading_title'] = $this->language->get('heading_title');
     $this->data['compare'] = $this->getUrl()->link('product/compare');
     $this->data['products'] = array();
     $data = array('sort' => $sort, 'order' => $order, 'start' => ($page - 1) * $limit, 'limit' => $limit);
     $customerGroupId = $this->getCurrentCustomer()->isLogged() ? $this->getCurrentCustomer()->getCustomerGroupId() : $this->getConfig()->get('config_customer_group_id');
     $product_total = ProductDAO::getInstance()->getProductsCount($data);
     $products = ProductDAO::getInstance()->getDiscountedProductsByCustomerGroupId($customerGroupId, $sort, $order, ($page - 1) * $limit, $limit);
     foreach ($products as $product) {
         #kabantejay synonymizer start
         if (is_null($product->getDescriptions()) || is_null($product->getDescriptions()->getDescription($this->getLanguage()->getId()))) {
             $productDescription = '';
         } else {
             $productDescription = preg_replace_callback('/\\{  (.*?)  \\}/xs', function ($m) {
                 $ar = explode("|", $m[1]);
                 return $ar[array_rand($ar, 1)];
             }, $product->getDescriptions()->getDescription($this->getLanguage()->getId())->getDescription());
         }
         #kabantejay synonymizer end
         if ($product->getImagePath()) {
             $image = ImageService::getInstance()->resize($product->getImagePath(), $this->getConfig()->get('config_image_product_width'), $this->getConfig()->get('config_image_product_height'));
         } else {
             $image = false;
         }
         if ($this->getConfig()->get('config_customer_price') && $this->customer->isLogged() || !$this->getConfig()->get('config_customer_price')) {
             $price = $this->getCurrency()->format($product->getPrice());
         } else {
             $price = false;
         }
         if ((double) $product->getSpecialPrice($customerGroupId)) {
             $special = $this->getCurrency()->format($product->getSpecialPrice($customerGroupId));
         } else {
             $special = false;
         }
         if ($this->getConfig()->get('config_tax')) {
             $tax = $this->getCurrency()->format((double) $product->getSpecialPrice($customerGroupId) ? $product->getSpecialPrice($customerGroupId) : $product->getPrice());
         } else {
             $tax = false;
         }
         $this->data['products'][] = array('product_id' => $product->getId(), 'thumb' => $image, 'name' => $product->getName(), 'description' => utf8_truncate(strip_tags(html_entity_decode($productDescription, ENT_QUOTES, 'UTF-8')), 400, '&nbsp;&hellip;', true), 'price' => $price, 'special' => $special, 'tax' => $tax, 'rating' => $product->getRating(), 'reviews' => sprintf($this->language->get('text_reviews'), (int) $product->getReviewsCount()), 'href' => $this->getUrl()->link('product/product', $url . '&product_id=' . $product->getId()));
     }
     $url = '';
     if (isset($this->request->get['limit'])) {
         $url .= '&limit=' . $this->request->get['limit'];
     }
     $this->data['sorts'] = array();
     $this->data['sorts'][] = array('text' => $this->language->get('text_default'), 'value' => 'p.sort_order-ASC', 'href' => $this->getUrl()->link('product/special', 'sort=p.sort_order&order=ASC' . $url));
     $this->data['sorts'][] = array('text' => $this->language->get('text_name_asc'), 'value' => 'pd.name-ASC', 'href' => $this->getUrl()->link('product/special', 'sort=pd.name&order=ASC' . $url));
     $this->data['sorts'][] = array('text' => $this->language->get('text_name_desc'), 'value' => 'pd.name-DESC', 'href' => $this->getUrl()->link('product/special', 'sort=pd.name&order=DESC' . $url));
     $this->data['sorts'][] = array('text' => $this->language->get('text_price_asc'), 'value' => 'ps.price-ASC', 'href' => $this->getUrl()->link('product/special', 'sort=ps.price&order=ASC' . $url));
     $this->data['sorts'][] = array('text' => $this->language->get('text_price_desc'), 'value' => 'special-DESC', 'href' => $this->getUrl()->link('product/special', 'sort=special&order=DESC' . $url));
     $this->data['sorts'][] = array('text' => $this->language->get('text_rating_desc'), 'value' => 'rating-DESC', 'href' => $this->getUrl()->link('product/special', 'sort=rating&order=DESC' . $url));
     $this->data['sorts'][] = array('text' => $this->language->get('text_rating_asc'), 'value' => 'rating-ASC', 'href' => $this->getUrl()->link('product/special', 'sort=rating&order=ASC' . $url));
     $this->data['sorts'][] = array('text' => $this->language->get('text_model_asc'), 'value' => 'p.model-ASC', 'href' => $this->getUrl()->link('product/special', 'sort=p.model&order=ASC' . $url));
     $this->data['sorts'][] = array('text' => $this->language->get('text_model_desc'), 'value' => 'p.model-DESC', 'href' => $this->getUrl()->link('product/special', 'sort=p.model&order=DESC' . $url));
     $url = '';
     if (isset($this->request->get['sort'])) {
         $url .= '&sort=' . $this->request->get['sort'];
     }
     if (isset($this->request->get['order'])) {
         $url .= '&order=' . $this->request->get['order'];
     }
     $this->data['limits'] = array();
     $this->data['limits'][] = array('text' => $this->getConfig()->get('config_catalog_limit'), 'value' => $this->getConfig()->get('config_catalog_limit'), 'href' => $this->getUrl()->link('product/special', $url . '&limit=' . $this->getConfig()->get('config_catalog_limit')));
     $this->data['limits'][] = array('text' => 25, 'value' => 25, 'href' => $this->getUrl()->link('product/special', $url . '&limit=25'));
     $this->data['limits'][] = array('text' => 50, 'value' => 50, 'href' => $this->getUrl()->link('product/special', $url . '&limit=50'));
     $this->data['limits'][] = array('text' => 75, 'value' => 75, 'href' => $this->getUrl()->link('product/special', $url . '&limit=75'));
     $this->data['limits'][] = array('text' => 100, 'value' => 100, 'href' => $this->getUrl()->link('product/special', $url . '&limit=100'));
     $url = '';
     if (isset($this->request->get['sort'])) {
         $url .= '&sort=' . $this->request->get['sort'];
     }
     if (isset($this->request->get['order'])) {
         $url .= '&order=' . $this->request->get['order'];
     }
     if (isset($this->request->get['limit'])) {
         $url .= '&limit=' . $this->request->get['limit'];
     }
     $pagination = new Pagination();
     $pagination->total = $product_total;
     $pagination->page = $page;
     $pagination->limit = $limit;
     $pagination->text = $this->language->get('text_pagination');
     $pagination->url = $this->getUrl()->link('product/special', $url . '&page={page}');
     $this->data['pagination'] = $pagination->render();
     $this->data['sort'] = $sort;
     $this->data['order'] = $order;
     $this->data['limit'] = $limit;
     $this->setBreadcrumbs();
     $this->children = array('common/column_left', 'common/column_right', 'common/content_top', 'common/content_bottom', 'common/footer', 'common/header');
     $this->getResponse()->setOutput($this->render($this->getConfig()->get('config_template') . '/template/product/special.tpl'));
 }
Esempio n. 14
0
 public function product()
 {
     $manufacturer = ManufacturerDAO::getInstance()->getManufacturer($this->parameters['manufacturerId']);
     if ($manufacturer) {
         if (!is_null($manufacturer->getDescription($this->getLanguage()->getId())) && !is_null($manufacturer->getDescription($this->getLanguage()->getId())->getSeoTitle())) {
             $this->document->setTitle($manufacturer->getDescription($this->getLanguage()->getId())->getSeoTitle());
         } else {
             $this->document->setTitle($manufacturer->getName());
         }
         if (!is_null($manufacturer->getDescription($this->getLanguage()->getId())) && !is_null($manufacturer->getDescription($this->getLanguage()->getId())->getMetaDescription())) {
             $this->document->setDescription($manufacturer->getDescription($this->getLanguage()->getId())->getMetaDescription());
         }
         if (!is_null($manufacturer->getDescription($this->getLanguage()->getId())) && !is_null($manufacturer->getDescription($this->getLanguage()->getId())->getMetaKeyword())) {
             $this->document->setKeywords($manufacturer->getDescription($this->getLanguage()->getId())->getMetaKeyword());
         }
         if (!is_null($manufacturer->getDescription($this->getLanguage()->getId())) && !is_null($manufacturer->getDescription($this->getLanguage()->getId())->getSeoH1())) {
             $this->data['seo_h1'] = $manufacturer->getDescription($this->getLanguage()->getId())->getSeoH1();
         }
         $this->data = array_merge($this->data, $this->parameters);
         $this->data['heading_title'] = $manufacturer->getName();
         $this->data['compare'] = $this->getUrl()->link('product/compare');
         $url = '';
         if (isset($this->request->get['sort'])) {
             $url .= '&sort=' . $this->request->get['sort'];
         }
         if (isset($this->request->get['order'])) {
             $url .= '&order=' . $this->request->get['order'];
         }
         if (isset($this->request->get['page'])) {
             $url .= '&page=' . $this->request->get['page'];
         }
         if (isset($this->request->get['limit'])) {
             $url .= '&limit=' . $this->request->get['limit'];
         }
         #kabantejay synonymizer start
         $this->data['description'] = preg_replace_callback('/\\{  (.*?)  \\}/xs', function ($m) {
             $ar = explode("|", $m[1]);
             return $ar[array_rand($ar, 1)];
         }, html_entity_decode(!is_null($manufacturer->getDescription($this->getLanguage()->getId())) ? $manufacturer->getDescription($this->getLanguage()->getId())->getDescription() : "", ENT_QUOTES, 'UTF-8'));
         #kabantejay synonymizer end
         $this->data['products'] = array();
         $data = array('filterManufacturerId' => $this->parameters['manufacturerId'], 'sort' => $this->parameters['sort'], 'order' => $this->parameters['order'], 'start' => ($this->parameters['page'] - 1) * $this->parameters['limit'], 'limit' => $this->parameters['limit']);
         $product_total = ProductDAO::getInstance()->getProductsCount($data);
         $products = ProductDAO::getInstance()->getProducts($data, $this->parameters['sort'], $this->parameters['order'], ($this->parameters['page'] - 1) * $this->parameters['limit'], $this->parameters['limit']);
         foreach ($products as $product) {
             if ($product->getImagePath()) {
                 $image = ImageService::getInstance()->resize($product->getImagePath(), $this->getConfig()->get('config_image_product_width'), $this->getConfig()->get('config_image_product_height'));
             } else {
                 $image = false;
             }
             if ($this->getConfig()->get('config_customer_price') && $this->customer->isLogged() || !$this->getConfig()->get('config_customer_price')) {
                 //					$price = $this->currency->format($this->tax->calculate($product->getPrice(), $product->getTaxClassId(), $this->getConfig()->get('config_tax')));
                 $price = $this->getCurrentCurrency()->format($product->getPrice());
             } else {
                 $price = false;
             }
             if ((double) $product->getSpecialPrice($this->getCurrentCustomer()->getCustomerGroupId())) {
                 //					$special = $this->currency->format($this->tax->calculate($product->getSpecials(), $product->getTaxClassId(), $this->getConfig()->get('config_tax')));
                 $special = $this->getCurrentCurrency()->format($product->getSpecialPrice($this->getCurrentCustomer()->getCustomerGroupId()));
             } else {
                 $special = false;
             }
             //				if ($this->getConfig()->get('config_tax')) {
             //					$tax = $this->currency->format((float)$product->getSpecial() ? $product->getSpecial() : $product->getPrice());
             //				} else {
             //					$tax = false;
             //				}
             //              #kabantejay synonymizer start
             if (is_null($product->getDescriptions())) {
                 $description = '';
             } else {
                 $description = preg_replace_callback('/\\{  (.*?)  \\}/xs', function ($m) {
                     $ar = explode("|", $m[1]);
                     return $ar[array_rand($ar, 1)];
                 }, $product->getDescriptions()->getDescription($this->getLanguage()->getId()));
             }
             //	   		#kabantejay synonymizer end
             $this->data['products'][] = array('product_id' => $product->getId(), 'thumb' => $image, 'name' => $product->getName(), 'description' => utf8_truncate(strip_tags(html_entity_decode($description, ENT_QUOTES, 'UTF-8')), 400, '&nbsp;&hellip;', true), 'price' => $price, 'special' => $special, 'rating' => $this->getConfig()->get('config_review_status') ? $product->getRating() : false, 'reviews' => sprintf($this->getLanguage()->get('text_reviews'), $product->getReviewsCount()), 'href' => $this->getUrl()->link('product/product', $url . '&manufacturer_id=' . $product->getManufacturer()->getId() . '&product_id=' . $product->getId()));
         }
         $url = '';
         if (isset($this->request->get['limit'])) {
             $url .= '&limit=' . $this->request->get['limit'];
         }
         $this->data['sorts'] = array();
         $this->data['sorts'][] = array('text' => $this->getLanguage()->get('text_default'), 'value' => 'p.sort_order-ASC', 'href' => $this->getUrl()->link('product/manufacturer/product', 'manufacturer_id=' . $this->request->get['manufacturer_id'] . '&sort=p.sort_order&order=ASC' . $url));
         $this->data['sorts'][] = array('text' => $this->getLanguage()->get('text_name_asc'), 'value' => 'pd.name-ASC', 'href' => $this->getUrl()->link('product/manufacturer/product', 'manufacturer_id=' . $this->request->get['manufacturer_id'] . '&sort=pd.name&order=ASC' . $url));
         $this->data['sorts'][] = array('text' => $this->getLanguage()->get('text_name_desc'), 'value' => 'pd.name-DESC', 'href' => $this->getUrl()->link('product/manufacturer/product', 'manufacturer_id=' . $this->request->get['manufacturer_id'] . '&sort=pd.name&order=DESC' . $url));
         $this->data['sorts'][] = array('text' => $this->getLanguage()->get('text_price_asc'), 'value' => 'p.price-ASC', 'href' => $this->getUrl()->link('product/manufacturer/product', 'manufacturer_id=' . $this->request->get['manufacturer_id'] . '&sort=p.price&order=ASC' . $url));
         $this->data['sorts'][] = array('text' => $this->getLanguage()->get('text_price_desc'), 'value' => 'p.price-DESC', 'href' => $this->getUrl()->link('product/manufacturer/product', 'manufacturer_id=' . $this->request->get['manufacturer_id'] . '&sort=p.price&order=DESC' . $url));
         $this->data['sorts'][] = array('text' => $this->getLanguage()->get('text_rating_desc'), 'value' => 'rating-DESC', 'href' => $this->getUrl()->link('product/manufacturer/product', 'manufacturer_id=' . $this->request->get['manufacturer_id'] . '&sort=rating&order=DESC' . $url));
         $this->data['sorts'][] = array('text' => $this->getLanguage()->get('text_rating_asc'), 'value' => 'rating-ASC', 'href' => $this->getUrl()->link('product/manufacturer/product', 'manufacturer_id=' . $this->request->get['manufacturer_id'] . '&sort=rating&order=ASC' . $url));
         $this->data['sorts'][] = array('text' => $this->getLanguage()->get('text_model_asc'), 'value' => 'p.model-ASC', 'href' => $this->getUrl()->link('product/manufacturer/product', 'manufacturer_id=' . $this->request->get['manufacturer_id'] . '&sort=p.model&order=ASC' . $url));
         $this->data['sorts'][] = array('text' => $this->getLanguage()->get('text_model_desc'), 'value' => 'p.model-DESC', 'href' => $this->getUrl()->link('product/manufacturer/product', 'manufacturer_id=' . $this->request->get['manufacturer_id'] . '&sort=p.model&order=DESC' . $url));
         $url = '';
         if (isset($this->request->get['sort'])) {
             $url .= '&sort=' . $this->request->get['sort'];
         }
         if (isset($this->request->get['order'])) {
             $url .= '&order=' . $this->request->get['order'];
         }
         $this->data['limits'] = array();
         $this->data['limits'][] = array('text' => $this->getConfig()->get('config_catalog_limit'), 'value' => $this->getConfig()->get('config_catalog_limit'), 'href' => $this->getUrl()->link('product/manufacturer/product', 'manufacturer_id=' . $this->request->get['manufacturer_id'] . $url . '&limit=' . $this->getConfig()->get('config_catalog_limit')));
         $this->data['limits'][] = array('text' => 25, 'value' => 25, 'href' => $this->getUrl()->link('product/manufacturer/product', 'manufacturer_id=' . $this->request->get['manufacturer_id'] . $url . '&limit=25'));
         $this->data['limits'][] = array('text' => 50, 'value' => 50, 'href' => $this->getUrl()->link('product/manufacturer/product', 'manufacturer_id=' . $this->request->get['manufacturer_id'] . $url . '&limit=50'));
         $this->data['limits'][] = array('text' => 75, 'value' => 75, 'href' => $this->getUrl()->link('product/manufacturer/product', 'manufacturer_id=' . $this->request->get['manufacturer_id'] . $url . '&limit=75'));
         $this->data['limits'][] = array('text' => 100, 'value' => 100, 'href' => $this->getUrl()->link('product/manufacturer/product', 'manufacturer_id=' . $this->request->get['manufacturer_id'] . $url . '&limit=100'));
         $url = '';
         if (isset($this->request->get['sort'])) {
             $url .= '&sort=' . $this->request->get['sort'];
         }
         if (isset($this->request->get['order'])) {
             $url .= '&order=' . $this->request->get['order'];
         }
         if (isset($this->request->get['limit'])) {
             $url .= '&limit=' . $this->request->get['limit'];
         }
         $this->setBreadcrumbs([['text' => $this->getLanguage()->get('text_brand'), 'route' => $this->getUrl()->link('product/manufacturer')]]);
         $pagination = new Pagination();
         $pagination->total = $product_total;
         $pagination->page = $this->parameters['page'];
         $pagination->limit = $this->parameters['limit'];
         $pagination->text = $this->getLanguage()->get('text_pagination');
         $pagination->url = $this->getUrl()->link('product/manufacturer/product', 'manufacturer_id=' . $this->request->get['manufacturer_id'] . $url . '&page={page}');
         $this->data['pagination'] = $pagination->render();
         $this->data['continue'] = $this->getUrl()->link('common/home');
         $this->children = array('common/column_left', 'common/column_right', 'common/content_top', 'common/content_bottom', 'common/footer', 'common/header');
         $templateFile = '/template/product/manufacturerInfo.tpl.php';
         $templateDir = file_exists(DIR_TEMPLATE . $this->getConfig()->get('config_template') . $templateFile) ? $this->getConfig()->get('config_template') : 'default';
         $this->getResponse()->setOutput($this->render($templateDir . $templateFile));
     } else {
         $this->document->setTitle($this->getLanguage()->get('text_error'));
         $this->data['heading_title'] = $this->getLanguage()->get('text_error');
         $this->data['continue'] = $this->getUrl()->link('common/home');
         $this->setBreadcrumbs();
         $this->children = array('common/column_left', 'common/column_right', 'common/content_top', 'common/content_bottom', 'common/footer', 'common/header');
         $templateFile = '/template/error/not_found.tpl';
         $templateDir = file_exists(DIR_TEMPLATE . $this->getConfig()->get('config_template') . $templateFile) ? $this->getConfig()->get('config_template') : 'default';
         $this->getResponse()->setOutput($this->render($templateDir . $templateFile));
     }
 }
Esempio n. 15
0
 public function index()
 {
     $this->language->load('product/category');
     $this->load->model('catalog/category');
     $this->load->model('catalog/product');
     $this->load->model('tool/image');
     $this->data['isSaler'] = $this->customer->getCustomerGroupId() == 6;
     if (isset($this->request->get['order'])) {
         $order = $this->request->get['order'];
     } else {
         $order = 'ASC';
     }
     if (isset($this->request->get['sort'])) {
         $sort = $this->request->get['sort'];
     } else {
         $sort = 'p.date_added';
         $order = 'DESC';
     }
     if (isset($this->request->get['page'])) {
         $page = $this->request->get['page'];
     } else {
         $page = 1;
     }
     if (isset($this->request->get['limit'])) {
         $limit = $this->request->get['limit'];
     } else {
         $limit = $this->config->get('config_catalog_limit');
     }
     $this->data['breadcrumbs'] = array();
     $this->data['breadcrumbs'][] = array('text' => $this->language->get('text_home'), 'href' => $this->url->link('common/home'), 'separator' => false);
     if (isset($this->request->get['path'])) {
         $path = '';
         $parts = explode('_', (string) $this->request->get['path']);
         foreach ($parts as $path_id) {
             if (!$path) {
                 $path = $path_id;
             } else {
                 $path .= '_' . $path_id;
             }
             $category_info = $this->model_catalog_category->getCategory($path_id);
             #kabantejay synonymizer start
             $razdel = isset($category_info['name']) ? $category_info['name'] : '';
             #kabantejay synonymizer end
             if ($category_info) {
                 $this->data['breadcrumbs'][] = array('text' => $category_info['name'], 'href' => $this->url->link('product/category', 'path=' . $path), 'separator' => $this->language->get('text_separator'));
             }
         }
         $category_id = array_pop($parts);
     } else {
         $category_id = 0;
     }
     $category_info = $this->model_catalog_category->getCategory($category_id);
     if ($category_info) {
         if ($category_info['seo_title']) {
             $this->document->setTitle($category_info['seo_title']);
         } else {
             $this->document->setTitle($category_info['name']);
         }
         $this->document->setDescription($category_info['meta_description']);
         $this->document->setKeywords($category_info['meta_keyword']);
         $this->data['seo_h1'] = $category_info['seo_h1'];
         $this->data['heading_title'] = $category_info['name'];
         $this->data['text_refine'] = $this->language->get('text_refine');
         $this->data['text_empty'] = $this->language->get('text_empty');
         $this->data['text_quantity'] = $this->language->get('text_quantity');
         $this->data['text_manufacturer'] = $this->language->get('text_manufacturer');
         $this->data['text_model'] = $this->language->get('text_model');
         $this->data['text_price'] = $this->language->get('text_price');
         $this->data['text_tax'] = $this->language->get('text_tax');
         $this->data['text_points'] = $this->language->get('text_points');
         $this->data['text_compare'] = sprintf($this->language->get('text_compare'), isset($this->session->data['compare']) ? count($this->session->data['compare']) : 0);
         $this->data['text_display'] = $this->language->get('text_display');
         $this->data['text_list'] = $this->language->get('text_list');
         $this->data['text_grid'] = $this->language->get('text_grid');
         $this->data['text_sort'] = $this->language->get('text_sort');
         $this->data['text_limit'] = $this->language->get('text_limit');
         $this->data['button_cart'] = $this->language->get('button_cart');
         $this->data['button_wishlist'] = $this->language->get('button_wishlist');
         $this->data['button_compare'] = $this->language->get('button_compare');
         $this->data['button_continue'] = $this->language->get('button_continue');
         if ($category_info['image']) {
             $this->data['thumb'] = $this->model_tool_image->resize($category_info['image'], $this->config->get('config_image_category_width'), $this->config->get('config_image_category_height'));
         } else {
             $this->data['thumb'] = '';
         }
         $this->data['description'] = html_entity_decode($category_info['description'], ENT_QUOTES, 'UTF-8');
         $this->data['compare'] = $this->url->link('product/compare');
         $url = '';
         if (isset($this->request->get['sort'])) {
             $url .= '&sort=' . $this->request->get['sort'];
         }
         if (isset($this->request->get['order'])) {
             $url .= '&order=' . $this->request->get['order'];
         }
         if (isset($this->request->get['limit'])) {
             $url .= '&limit=' . $this->request->get['limit'];
         }
         $this->data['categories'] = array();
         $results = $this->model_catalog_category->getCategories($category_id);
         foreach ($results as $result) {
             $data = array('filter_category_id' => $result['category_id'], 'filter_sub_category' => true);
             $product_total = $this->model_catalog_product->getTotalProducts($data);
             $this->data['categories'][] = array('name' => $result['name'] . ' (' . $product_total . ')', 'href' => $this->url->link('product/category', 'path=' . $this->request->get['path'] . '_' . $result['category_id'] . $url));
         }
         $this->data['products'] = array();
         #kabantejay synonymizer start
         $this->data['description'] = preg_replace_callback('/\\{  (.*?)  \\}/xs', function ($m) {
             $ar = explode("|", $m[1]);
             return $ar[array_rand($ar, 1)];
         }, $this->data['description']);
         #kabantejay synonymizer end
         $data = array('filter_category_id' => $category_id, 'sort' => $sort, 'order' => $order, 'start' => ($page - 1) * $limit, 'limit' => $limit, 'nocache' => 1);
         $product_total = $this->model_catalog_product->getTotalProducts($data);
         $results = $this->model_catalog_product->getProducts($data);
         foreach ($results as $result) {
             if ($result['image']) {
                 $image = $this->model_tool_image->resize($result['image'], $this->config->get('config_image_product_width'), $this->config->get('config_image_product_height'));
             } else {
                 $image = false;
             }
             if ($this->config->get('config_customer_price') && $this->customer->isLogged() || !$this->config->get('config_customer_price')) {
                 $price = $this->getCurrency()->format($this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax')));
             } else {
                 $price = false;
             }
             if ((double) $result['special']) {
                 $special = $this->getCurrency()->format($this->tax->calculate($result['special'], $result['tax_class_id'], $this->config->get('config_tax')));
             } else {
                 $special = false;
             }
             if ($this->config->get('config_tax')) {
                 $tax = $this->getCurrency()->format((double) $result['special'] ? $result['special'] : $result['price']);
             } else {
                 $tax = false;
             }
             //				if ($this->config->get('config_review_status')) {
             //					$rating = (int)$result['rating'];
             //				} else {
             //					$rating = false;
             //				}
             $date_added = getdate(strtotime($result['date_added']));
             $date_added = mktime(0, 0, 0, $date_added['mon'], $date_added['mday'], $date_added['year']);
             #kabantejay synonymizer start
             if (!isset($result['manufacturer'])) {
                 $brand = '';
             } else {
                 $brand = $result['manufacturer'];
             }
             if (!isset($razdel)) {
                 $razdel = '';
             }
             if (!isset($result['name'])) {
                 $syncat = '';
             } else {
                 $syncat = $category_info['name'];
             }
             if (!isset($result['model'])) {
                 $synmod = '';
             } else {
                 $synmod = $result['model'];
             }
             if ($special == false) {
                 $synprice = $price;
             } else {
                 $synprice = $special;
             }
             $syntext = array(array("%H1%", $result['name']), array("%BRAND%", $brand), array("%RAZDEL%", $razdel), array("%CATEGORY%", $syncat), array("%MODEL%", $synmod), array("%PRICE%", $synprice));
             for ($it = 0; $it < 6; $it++) {
                 $result['description'] = str_replace($syntext[$it][0], $syntext[$it][1], $result['description']);
             }
             $result['description'] = preg_replace_callback('/\\{  (.*?)  \\}/xs', function ($m) {
                 $ar = explode("|", $m[1]);
                 return $ar[array_rand($ar, 1)];
             }, $result['description']);
             #kabantejay synonymizer end
             $this->data['products'][] = array('product_id' => $result['product_id'], 'thumb' => $image, 'name' => $result['name'], 'description' => utf8_truncate(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8')), 400, '&nbsp;&hellip;', true), 'price' => $price, 'isSaler' => $this->data['isSaler'], 'special' => $special, 'tax' => $tax, 'rating' => $result['rating'], 'reviews' => sprintf($this->language->get('text_reviews'), (int) $result['reviews']), 'href' => $this->url->link('product/product', 'path=' . $this->request->get['path'] . '&product_id=' . $result['product_id']), 'hot' => $date_added + 86400 * $this->config->get('config_product_hotness_age') > time());
         }
         $url = '';
         if (isset($this->request->get['limit'])) {
             $url .= '&limit=' . $this->request->get['limit'];
         }
         $this->data['sorts'] = array();
         $this->data['sorts'][] = array('text' => $this->language->get('text_default'), 'value' => 'p.sort_order-ASC', 'href' => $this->url->link('product/category', 'path=' . $this->request->get['path'] . '&sort=p.sort_order&order=ASC' . $url));
         $this->data['sorts'][] = array('text' => $this->language->get('text_name_asc'), 'value' => 'pd.name-ASC', 'href' => $this->url->link('product/category', 'path=' . $this->request->get['path'] . '&sort=pd.name&order=ASC' . $url));
         $this->data['sorts'][] = array('text' => $this->language->get('text_name_desc'), 'value' => 'pd.name-DESC', 'href' => $this->url->link('product/category', 'path=' . $this->request->get['path'] . '&sort=pd.name&order=DESC' . $url));
         $this->data['sorts'][] = array('text' => $this->language->get('text_price_asc'), 'value' => 'p.price-ASC', 'href' => $this->url->link('product/category', 'path=' . $this->request->get['path'] . '&sort=p.price&order=ASC' . $url));
         $this->data['sorts'][] = array('text' => $this->language->get('text_price_desc'), 'value' => 'p.price-DESC', 'href' => $this->url->link('product/category', 'path=' . $this->request->get['path'] . '&sort=p.price&order=DESC' . $url));
         $this->data['sorts'][] = array('text' => $this->language->get('text_rating_desc'), 'value' => 'rating-DESC', 'href' => $this->url->link('product/category', 'path=' . $this->request->get['path'] . '&sort=rating&order=DESC' . $url));
         $this->data['sorts'][] = array('text' => $this->language->get('text_rating_asc'), 'value' => 'rating-ASC', 'href' => $this->url->link('product/category', 'path=' . $this->request->get['path'] . '&sort=rating&order=ASC' . $url));
         $this->data['sorts'][] = array('text' => $this->language->get('text_model_asc'), 'value' => 'p.model-ASC', 'href' => $this->url->link('product/category', 'path=' . $this->request->get['path'] . '&sort=p.model&order=ASC' . $url));
         $this->data['sorts'][] = array('text' => $this->language->get('text_model_desc'), 'value' => 'p.model-DESC', 'href' => $this->url->link('product/category', 'path=' . $this->request->get['path'] . '&sort=p.model&order=DESC' . $url));
         $url = '';
         if (isset($this->request->get['sort'])) {
             $url .= '&sort=' . $this->request->get['sort'];
         }
         if (isset($this->request->get['order'])) {
             $url .= '&order=' . $this->request->get['order'];
         }
         $this->data['limits'] = array();
         $this->data['limits'][] = array('text' => $this->config->get('config_catalog_limit'), 'value' => $this->config->get('config_catalog_limit'), 'href' => $this->url->link('product/category', 'path=' . $this->request->get['path'] . $url . '&limit=' . $this->config->get('config_catalog_limit')));
         $this->data['limits'][] = array('text' => 25, 'value' => 25, 'href' => $this->url->link('product/category', 'path=' . $this->request->get['path'] . $url . '&limit=25'));
         $this->data['limits'][] = array('text' => 50, 'value' => 50, 'href' => $this->url->link('product/category', 'path=' . $this->request->get['path'] . $url . '&limit=50'));
         $this->data['limits'][] = array('text' => 75, 'value' => 75, 'href' => $this->url->link('product/category', 'path=' . $this->request->get['path'] . $url . '&limit=75'));
         $this->data['limits'][] = array('text' => 100, 'value' => 100, 'href' => $this->url->link('product/category', 'path=' . $this->request->get['path'] . $url . '&limit=100'));
         $url = '';
         if (isset($this->request->get['sort'])) {
             $url .= '&sort=' . $this->request->get['sort'];
         }
         if (isset($this->request->get['order'])) {
             $url .= '&order=' . $this->request->get['order'];
         }
         if (isset($this->request->get['limit'])) {
             $url .= '&limit=' . $this->request->get['limit'];
         }
         $pagination = new Pagination();
         $pagination->total = $product_total;
         $pagination->page = $page;
         $pagination->limit = $limit;
         $pagination->text = $this->language->get('text_pagination');
         $pagination->url = $this->url->link('product/category', 'path=' . $this->request->get['path'] . $url . '&page={page}');
         $this->data['pagination'] = $pagination->render();
         $this->data['sort'] = $sort;
         $this->data['order'] = $order;
         $this->data['limit'] = $limit;
         $this->data['continue'] = $this->url->link('common/home');
         $templateName = '/template/product/category.tpl';
         if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . $templateName)) {
             $this->template = $this->config->get('config_template') . $templateName;
         } else {
             $this->template = 'default' . $templateName;
         }
         $this->children = array('common/column_left', 'common/column_right', 'common/content_top', 'common/content_bottom', 'common/footer', 'common/header');
         $this->load->language('shop/general');
         $this->data['text_button_download'] = $this->language->get('text_button_download');
         $this->data['isSaler'] = $this->customer->getCustomerGroupId() == 6;
         $this->data['showDownload'] = false;
         if ($this->request->get['route'] == "product/category" || $this->request->get['route'] == "common/home") {
             $this->data['showDownload'] = true;
         }
         $this->getResponse()->setOutput($this->render());
     } else {
         $url = '';
         if (isset($this->request->get['path'])) {
             $url .= '&path=' . $this->request->get['path'];
         }
         if (isset($this->request->get['sort'])) {
             $url .= '&sort=' . $this->request->get['sort'];
         }
         if (isset($this->request->get['order'])) {
             $url .= '&order=' . $this->request->get['order'];
         }
         if (isset($this->request->get['page'])) {
             $url .= '&page=' . $this->request->get['page'];
         }
         if (isset($this->request->get['limit'])) {
             $url .= '&limit=' . $this->request->get['limit'];
         }
         $this->data['breadcrumbs'][] = array('text' => $this->language->get('text_error'), 'href' => $this->url->link('product/category', $url), 'separator' => $this->language->get('text_separator'));
         $this->document->setTitle($this->language->get('text_error'));
         $this->data['heading_title'] = $this->language->get('text_error');
         $this->data['text_error'] = $this->language->get('text_error');
         $this->data['button_continue'] = $this->language->get('button_continue');
         $this->data['continue'] = $this->url->link('common/home');
         if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/error/not_found.tpl')) {
             $this->template = $this->config->get('config_template') . '/template/error/not_found.tpl';
         } else {
             $this->template = 'default/template/error/not_found.tpl';
         }
         $this->children = array('common/column_left', 'common/column_right', 'common/content_top', 'common/content_bottom', 'common/footer', 'common/header');
         $this->load->language('shop/general');
         $this->data['text_button_download'] = $this->language->get('text_button_download');
         $this->data['isSaler'] = $this->customer->getCustomerGroupId() == 6;
         $this->data['showDownload'] = false;
         if (isset($this->request->get['route']) && ($this->request->get['route'] == "product/category" || $this->request->get['route'] == "common/home")) {
             $this->data['showDownload'] = true;
         }
         $this->getResponse()->setOutput($this->render());
     }
 }
Esempio n. 16
0
 private function sendMail($orderInfo, $comment, $notify)
 {
     // Send out order confirmation mail
     $language = new Language($orderInfo['language_directory']);
     $language->load($orderInfo['language_filename']);
     $language->load('mail/order');
     $order_status_query = $this->getDb()->query("SELECT * FROM order_status WHERE order_status_id = '" . (int) $orderInfo['order_status_id'] . "' AND language_id = '" . (int) $orderInfo['language_id'] . "'");
     if ($order_status_query->num_rows) {
         $order_status = $order_status_query->row['name'];
     } else {
         $order_status = '';
     }
     $order_product_query = $this->getDb()->query("SELECT * FROM order_product WHERE order_id = " . (int) $orderInfo['order_id']);
     $order_total_query = $this->getDb()->query("SELECT * FROM order_total WHERE order_id = " . (int) $orderInfo['order_id'] . " ORDER BY sort_order ASC");
     $order_download_query = $this->getDb()->query("SELECT * FROM order_download WHERE order_id = " . (int) $orderInfo['order_id']);
     $subject = sprintf($language->get('text_new_subject'), $orderInfo['store_name'], $orderInfo['order_id']);
     // HTML Mail
     $template = new Template();
     $template->data['title'] = sprintf($language->get('text_new_subject'), html_entity_decode($orderInfo['store_name'], ENT_QUOTES, 'UTF-8'), $orderInfo['order_id']);
     $template->data['text_greeting'] = sprintf($language->get('text_new_greeting'), html_entity_decode($orderInfo['store_name'], ENT_QUOTES, 'UTF-8'));
     $template->data['text_link'] = $language->get('text_new_link');
     $template->data['text_download'] = $language->get('text_new_download');
     $template->data['text_order_detail'] = $language->get('text_new_order_detail');
     $template->data['text_instruction'] = $language->get('text_new_instruction');
     $template->data['text_order_id'] = $language->get('text_new_order_id');
     $template->data['text_date_added'] = $language->get('text_new_date_added');
     $template->data['text_payment_method'] = $language->get('text_new_payment_method');
     $template->data['text_shipping_method'] = $language->get('text_new_shipping_method');
     $template->data['text_email'] = $language->get('text_new_email');
     $template->data['text_telephone'] = $language->get('text_new_telephone');
     $template->data['text_ip'] = $language->get('text_new_ip');
     $template->data['text_payment_address'] = $language->get('text_new_payment_address');
     $template->data['text_shipping_address'] = $language->get('text_new_shipping_address');
     $template->data['text_product'] = $language->get('text_new_product');
     $template->data['text_model'] = $language->get('text_new_model');
     $template->data['text_quantity'] = $language->get('text_new_quantity');
     $template->data['text_price'] = $language->get('text_new_price');
     $template->data['text_total'] = $language->get('text_new_total');
     $template->data['text_footer'] = $language->get('text_new_footer');
     $template->data['text_powered'] = $language->get('text_new_powered');
     $template->data['logo'] = 'cid:' . md5(basename($this->config->get('config_logo')));
     $template->data['store_name'] = $orderInfo['store_name'];
     $template->data['store_url'] = $orderInfo['store_url'];
     $template->data['customer_id'] = $orderInfo['customer_id'];
     $template->data['link'] = $orderInfo['store_url'] . 'index.php?route=account/order/info&order_id=' . $orderInfo['order_id'];
     if ($order_download_query->num_rows) {
         $template->data['download'] = $orderInfo['store_url'] . 'index.php?route=account/download';
     } else {
         $template->data['download'] = '';
     }
     $template->data['order_id'] = $orderInfo['order_id'];
     $template->data['date_added'] = date($language->get('date_format_short'), strtotime($orderInfo['date_added']));
     $template->data['payment_method'] = $orderInfo['payment_method'];
     $template->data['shipping_method'] = $orderInfo['shipping_method'];
     $template->data['email'] = $orderInfo['email'];
     $template->data['telephone'] = $orderInfo['telephone'];
     $template->data['ip'] = $orderInfo['ip'];
     if ($comment && $notify) {
         $template->data['comment'] = nl2br($comment);
     } else {
         $template->data['comment'] = '';
     }
     if ($orderInfo['shipping_address_format']) {
         $format = $orderInfo['shipping_address_format'];
     } else {
         $format = '{firstname} {lastname}' . "\n" . '{company}' . "\n" . '{address_1}' . "\n" . '{address_2}' . "\n" . '{city} {postcode}' . "\n" . '{zone}' . "\n" . '{country}';
     }
     $find = array('{firstname}', '{lastname}', '{company}', '{address_1}', '{address_2}', '{city}', '{postcode}', '{zone}', '{zone_code}', '{country}');
     $replace = array('firstname' => $orderInfo['shipping_firstname'], 'lastname' => $orderInfo['shipping_lastname'], 'company' => $orderInfo['shipping_company'], 'address_1' => $orderInfo['shipping_address_1'], 'address_2' => $orderInfo['shipping_address_2'], 'city' => $orderInfo['shipping_city'], 'postcode' => $orderInfo['shipping_postcode'], 'zone' => $orderInfo['shipping_zone'], 'zone_code' => $orderInfo['shipping_zone_code'], 'country' => $orderInfo['shipping_country']);
     $template->data['shipping_address'] = str_replace(array("\r\n", "\r", "\n"), '<br />', preg_replace(array("/\\s\\s+/", "/\r\r+/", "/\n\n+/"), '<br />', trim(str_replace($find, $replace, $format))));
     if ($orderInfo['payment_address_format']) {
         $format = $orderInfo['payment_address_format'];
     } else {
         $format = '{firstname} {lastname}' . "\n" . '{company}' . "\n" . '{address_1}' . "\n" . '{address_2}' . "\n" . '{city} {postcode}' . "\n" . '{zone}' . "\n" . '{country}';
     }
     $find = array('{firstname}', '{lastname}', '{company}', '{address_1}', '{address_2}', '{city}', '{postcode}', '{zone}', '{zone_code}', '{country}');
     $replace = array('firstname' => $orderInfo['payment_firstname'], 'lastname' => $orderInfo['payment_lastname'], 'company' => $orderInfo['payment_company'], 'address_1' => $orderInfo['payment_address_1'], 'address_2' => $orderInfo['payment_address_2'], 'city' => $orderInfo['payment_city'], 'postcode' => $orderInfo['payment_postcode'], 'zone' => $orderInfo['payment_zone'], 'zone_code' => $orderInfo['payment_zone_code'], 'country' => $orderInfo['payment_country']);
     $template->data['payment_address'] = str_replace(array("\r\n", "\r", "\n"), '<br />', preg_replace(array("/\\s\\s+/", "/\r\r+/", "/\n\n+/"), '<br />', trim(str_replace($find, $replace, $format))));
     $template->data['products'] = array();
     foreach ($order_product_query->rows as $product) {
         $option_data = array();
         $order_option_query = $this->getDb()->query("SELECT * FROM order_option WHERE order_id = '" . (int) $orderInfo['order_id'] . "' AND order_product_id = '" . (int) $product['order_product_id'] . "'");
         foreach ($order_option_query->rows as $option) {
             if ($option['type'] != 'file') {
                 $option_data[] = array('name' => $option['name'], 'value' => utf8_truncate($option['value']));
             } else {
                 $filename = substr($option['value'], 0, strrpos($option['value'], '.'));
                 $option_data[] = array('name' => $option['name'], 'value' => utf8_truncate($filename));
             }
         }
         $template->data['products'][] = array('name' => $product['name'], 'model' => $product['model'], 'option' => $option_data, 'quantity' => $product['quantity'], 'price' => $this->currency->format($product['price'], $orderInfo['currency_code'], $orderInfo['currency_value']), 'total' => $this->currency->format($product['total'], $orderInfo['currency_code'], $orderInfo['currency_value']));
     }
     $template->data['totals'] = $order_total_query->rows;
     if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/mail/order.tpl')) {
         $html = $template->fetch($this->config->get('config_template') . '/template/mail/order.tpl');
     } else {
         $html = $template->fetch('default/template/mail/order.tpl');
     }
     // Text Mail
     $text = sprintf($language->get('text_new_greeting'), html_entity_decode($orderInfo['store_name'], ENT_QUOTES, 'UTF-8')) . "\n\n";
     $text .= $language->get('text_new_order_id') . ' ' . $orderInfo['order_id'] . "\n";
     $text .= $language->get('text_new_date_added') . ' ' . date($language->get('date_format_short'), strtotime($orderInfo['date_added'])) . "\n";
     $text .= $language->get('text_new_order_status') . ' ' . $order_status . "\n\n";
     if ($comment && $notify) {
         $text .= $language->get('text_new_instruction') . "\n\n";
         $text .= $comment . "\n\n";
     }
     $text .= $language->get('text_new_products') . "\n";
     foreach ($order_product_query->rows as $result) {
         $text .= $result['quantity'] . 'x ' . $result['name'] . ' (' . $result['model'] . ') ' . html_entity_decode($this->currency->format($result['total'], $orderInfo['currency_code'], $orderInfo['currency_value']), ENT_NOQUOTES, 'UTF-8') . "\n";
         $order_option_query = $this->getDb()->query("SELECT * FROM order_option WHERE order_id = '" . (int) $orderInfo['order_id'] . "' AND order_product_id = '" . $result['order_product_id'] . "'");
         foreach ($order_option_query->rows as $option) {
             $text .= chr(9) . '-' . $option['name'] . ' ' . utf8_truncate($option['value']) . "\n";
         }
     }
     $text .= "\n";
     $text .= $language->get('text_new_order_total') . "\n";
     foreach ($order_total_query->rows as $result) {
         $text .= $result['title'] . ' ' . html_entity_decode($result['text'], ENT_NOQUOTES, 'UTF-8') . "\n";
     }
     $text .= "\n";
     if ($orderInfo['customer_id']) {
         $text .= $language->get('text_new_link') . "\n";
         $text .= $orderInfo['store_url'] . 'index.php?route=account/order/info&order_id=' . $orderInfo['order_id'] . "\n\n";
     }
     if ($order_download_query->num_rows) {
         $text .= $language->get('text_new_download') . "\n";
         $text .= $orderInfo['store_url'] . 'index.php?route=account/download' . "\n\n";
     }
     if ($orderInfo['comment']) {
         $text .= $language->get('text_new_comment') . "\n\n";
         $text .= $orderInfo['comment'] . "\n\n";
     }
     $text .= $language->get('text_new_footer') . "\n\n";
     $mail = new Mail();
     $mail->protocol = $this->config->get('config_mail_protocol');
     $mail->parameter = $this->config->get('config_mail_parameter');
     $mail->hostname = $this->config->get('config_smtp_host');
     $mail->username = $this->config->get('config_smtp_username');
     $mail->password = $this->config->get('config_smtp_password');
     $mail->port = $this->config->get('config_smtp_port');
     $mail->timeout = $this->config->get('config_smtp_timeout');
     $mail->setTo($orderInfo['email']);
     $mail->setFrom($this->config->get('config_email'));
     $mail->setSender($orderInfo['store_name']);
     $mail->setSubject($subject);
     $mail->setHtml($html);
     $mail->setText(html_entity_decode($text, ENT_QUOTES, 'UTF-8'));
     $mail->addAttachment(DIR_IMAGE . $this->config->get('config_logo'), md5(basename($this->config->get('config_logo'))));
     $mail->send();
     // Admin Alert Mail
     if ($this->config->get('config_alert_mail')) {
         $subject = sprintf($language->get('text_new_subject'), html_entity_decode($this->config->get('config_name'), ENT_QUOTES, 'UTF-8'), $orderInfo['order_id']);
         // Text
         $text = $language->get('text_new_received') . "\n\n";
         $text .= $language->get('text_new_order_id') . ' ' . $orderInfo['order_id'] . "\n";
         $text .= $language->get('text_new_date_added') . ' ' . date($language->get('date_format_short'), strtotime($orderInfo['date_added'])) . "\n";
         $text .= $language->get('text_new_order_status') . ' ' . $order_status . "\n\n";
         $text .= $language->get('text_new_products') . "\n";
         foreach ($order_product_query->rows as $result) {
             $text .= $result['quantity'] . 'x ' . $result['name'] . ' (' . $result['model'] . ') ' . html_entity_decode($this->currency->format($result['total'], $orderInfo['currency_code'], $orderInfo['currency_value']), ENT_NOQUOTES, 'UTF-8') . "\n";
             $order_option_query = $this->getDb()->query("SELECT * FROM order_option WHERE order_id = '" . (int) $orderInfo['order_id'] . "' AND order_product_id = '" . $result['order_product_id'] . "'");
             foreach ($order_option_query->rows as $option) {
                 $text .= chr(9) . '-' . $option['name'] . ' ' . utf8_truncate($option['value']) . "\n";
             }
         }
         $text .= "\n";
         $text .= $language->get('text_new_order_total') . "\n";
         foreach ($order_total_query->rows as $result) {
             $text .= $result['title'] . ' ' . html_entity_decode($result['text'], ENT_NOQUOTES, 'UTF-8') . "\n";
         }
         $text .= "\n";
         if ($orderInfo['comment'] != '') {
             $comment = $orderInfo['comment'] . "\n\n" . $comment;
         }
         if ($comment) {
             $text .= $language->get('text_new_comment') . "\n\n";
             $text .= $comment . "\n\n";
         }
         $mail = new Mail();
         $mail->protocol = $this->config->get('config_mail_protocol');
         $mail->parameter = $this->config->get('config_mail_parameter');
         $mail->hostname = $this->config->get('config_smtp_host');
         $mail->username = $this->config->get('config_smtp_username');
         $mail->password = $this->config->get('config_smtp_password');
         $mail->port = $this->config->get('config_smtp_port');
         $mail->timeout = $this->config->get('config_smtp_timeout');
         $mail->setTo($this->config->get('config_email'));
         $mail->setFrom($this->config->get('config_email'));
         $mail->setSender($orderInfo['store_name']);
         $mail->setSubject($subject);
         $mail->setText($text);
         $mail->send();
         // Send to additional alert emails
         $emails = explode(',', $this->config->get('config_alert_emails'));
         foreach ($emails as $email) {
             if ($email && preg_match('/^[^\\@]+@.*\\.[a-z]{2,6}$/i', $email)) {
                 $mail->setTo($email);
                 $mail->send();
             }
         }
     }
 }
Esempio n. 17
0
 function GetMessage($folderid, $id, $truncsize, $bodypreference = false, $optionbodypreference = false, $mimesupport = 0)
 {
     debugLog('iConDir::GetMessage(' . $folderid . ', ' . $this->_items[$id] . ', ..)');
     if ($folderid != "root") {
         return;
     }
     $types = array('dom' => 'type', 'intl' => 'type', 'postal' => 'type', 'parcel' => 'type', 'home' => 'type', 'work' => 'type', 'pref' => 'type', 'voice' => 'type', 'fax' => 'type', 'msg' => 'type', 'cell' => 'type', 'pager' => 'type', 'bbs' => 'type', 'modem' => 'type', 'car' => 'type', 'isdn' => 'type', 'video' => 'type', 'aol' => 'type', 'applelink' => 'type', 'attmail' => 'type', 'cis' => 'type', 'eworld' => 'type', 'internet' => 'type', 'ibmmail' => 'type', 'mcimail' => 'type', 'powershare' => 'type', 'prodigy' => 'type', 'tlx' => 'type', 'x400' => 'type', 'gif' => 'type', 'cgm' => 'type', 'wmf' => 'type', 'bmp' => 'type', 'met' => 'type', 'pmb' => 'type', 'dib' => 'type', 'pict' => 'type', 'tiff' => 'type', 'pdf' => 'type', 'ps' => 'type', 'jpeg' => 'type', 'qtime' => 'type', 'mpeg' => 'type', 'mpeg2' => 'type', 'avi' => 'type', 'wave' => 'type', 'aiff' => 'type', 'pcm' => 'type', 'x509' => 'type', 'pgp' => 'type', 'text' => 'value', 'inline' => 'value', 'url' => 'value', 'cid' => 'value', 'content-id' => 'value', '7bit' => 'encoding', '8bit' => 'encoding', 'quoted-printable' => 'encoding', 'base64' => 'encoding');
     // Parse the vcard
     $message = new SyncContact();
     $data = file_get_contents($this->_path . "/" . $this->_items[$id]);
     $data = str_replace("", '', $data);
     $data = str_replace("\r\n", "\n", $data);
     $data = str_replace("\r", "\n", $data);
     $data = preg_replace('/(\\n)([ \\t])/i', '', $data);
     $data = utf8_decode($data);
     $lines = explode("\n", $data);
     $vcard = array();
     foreach ($lines as $line) {
         if (trim($line) == '') {
             continue;
         }
         $pos = strpos($line, ':');
         if ($pos === false) {
             continue;
         }
         $field = trim(substr($line, 0, $pos));
         $value = trim(substr($line, $pos + 1));
         $fieldparts = preg_split('/(?<!\\\\)(\\;)/i', $field, -1, PREG_SPLIT_NO_EMPTY);
         $type = strtolower(array_shift($fieldparts));
         $fieldvalue = array();
         foreach ($fieldparts as $fieldpart) {
             if (preg_match('/([^=]+)=(.+)/', $fieldpart, $matches)) {
                 if (!in_array(strtolower($matches[1]), array('value', 'type', 'encoding', 'language'))) {
                     continue;
                 }
                 if (isset($fieldvalue[strtolower($matches[1])]) && is_array($fieldvalue[strtolower($matches[1])])) {
                     $fieldvalue[strtolower($matches[1])] = array_merge($fieldvalue[strtolower($matches[1])], preg_split('/(?<!\\\\)(\\,)/i', $matches[2], -1, PREG_SPLIT_NO_EMPTY));
                 } else {
                     $fieldvalue[strtolower($matches[1])] = preg_split('/(?<!\\\\)(\\,)/i', $matches[2], -1, PREG_SPLIT_NO_EMPTY);
                 }
             } else {
                 if (!isset($types[strtolower($fieldpart)])) {
                     continue;
                 }
                 $fieldvalue[$types[strtolower($fieldpart)]][] = $fieldpart;
             }
         }
         //
         switch ($type) {
             case 'categories':
                 //case 'nickname':
                 $val = preg_split('/(?<!\\\\)(\\,)/i', $value);
                 $val = array_map("w2ui", $val);
                 break;
             default:
                 $val = preg_split('/(?<!\\\\)(\\;)/i', $value);
                 break;
         }
         if (isset($fieldvalue['encoding'][0])) {
             switch (strtolower($fieldvalue['encoding'][0])) {
                 case 'q':
                 case 'quoted-printable':
                     foreach ($val as $i => $v) {
                         $val[$i] = quoted_printable_decode($v);
                     }
                     break;
                 case 'b':
                 case 'base64':
                     foreach ($val as $i => $v) {
                         $val[$i] = base64_decode($v);
                     }
                     break;
             }
         } else {
             foreach ($val as $i => $v) {
                 $val[$i] = $this->unescape($v);
             }
         }
         $fieldvalue['val'] = $val;
         $vcard[$type][] = $fieldvalue;
     }
     $fieldmapping = $this->_mapping;
     foreach ($fieldmapping as $k => $v) {
         switch ($v) {
             case 'body':
                 if ($bodypreference == false) {
                     $message->body = w2u(str_replace("\n", "\r\n", str_replace("\r", "", $vcard[$k][0]['val'][0])));
                     $message->bodysize = strlen($message->body);
                     $message->bodytruncated = 0;
                 } else {
                     $message->airsyncbasebody = new SyncAirSyncBaseBody();
                     debugLog("airsyncbasebody!");
                     $message->airsyncbasenativebodytype = 1;
                     if (isset($bodypreference[2])) {
                         debugLog("HTML Body");
                         // Send HTML if requested and native type was html
                         $message->airsyncbasebody->type = 2;
                         $html = '<html>' . '<head>' . '<meta name="Generator" content="Z-Push">' . '<meta http-equiv="Content-Type" content="text/html; charset=utf-8">' . '</head>' . '<body>' . str_replace("\n", "<BR>", str_replace("\r", "<BR>", str_replace("\r\n", "<BR>", w2u($vcard[$k][0]['val'][0])))) . '</body>' . '</html>';
                         if (isset($bodypreference[2]["TruncationSize"]) && strlen($html) > $bodypreference[2]["TruncationSize"]) {
                             $html = utf8_truncate($html, $bodypreference[2]["TruncationSize"]);
                             $message->airsyncbasebody->truncated = 1;
                         }
                         $message->airsyncbasebody->data = $html;
                         $message->airsyncbasebody->estimateddatasize = strlen($html);
                     } else {
                         // Send Plaintext as Fallback or if original body is plaintext
                         debugLog("Plaintext Body");
                         $plain = w2u(str_replace("\n", "\r\n", str_replace("\r", "", $vcard[$k][0]['val'][0])));
                         $message->airsyncbasebody->type = 1;
                         if (isset($bodypreference[1]["TruncationSize"]) && strlen($plain) > $bodypreference[1]["TruncationSize"]) {
                             $plain = utf8_truncate($plain, $bodypreference[1]["TruncationSize"]);
                             $message->airsyncbasebody->truncated = 1;
                         }
                         $message->airsyncbasebody->estimateddatasize = strlen($plain);
                         $message->airsyncbasebody->data = $plain;
                     }
                     // In case we have nothing for the body, send at least a blank...
                     // dw2412 but only in case the body is not rtf!
                     if ($message->airsyncbasebody->type != 3 && (!isset($message->airsyncbasebody->data) || strlen($message->airsyncbasebody->data) == 0)) {
                         $message->airsyncbasebody->data = " ";
                     }
                 }
                 break;
             case 'birthday':
                 if (!empty($vcard[$k][0]['val'][0])) {
                     $tz = date_default_timezone_get();
                     date_default_timezone_set('UTC');
                     $message->{$fieldmapping}[$k] = strtotime($vcard[$k][0]['val'][0]);
                     date_default_timezone_set($tz);
                 }
                 break;
             case 'picture':
                 $message->{$fieldmapping}[$k] = !empty($vcard[$k][0]['val'][0]) ? base64_encode($vcard[$k][0]['val'][0]) : NULL;
                 break;
             default:
                 $message->{$fieldmapping}[$k] = !empty($vcard[$k][0]['val'][0]) ? w2u($vcard[$k][0]['val'][0]) : NULL;
         }
     }
     return $message;
 }
Esempio n. 18
0
 function GetMessage($folderid, $id, $truncsize, $bodypreference = false, $optionbodypreference = false, $mimesupport = 0)
 {
     debugLog('GContacts::GetMessage(' . $folderid . ', ' . $this->_items[$id] . ', ..)');
     if ($folderid != "root") {
         return;
     }
     debugLog("GContacts::GetMessage: (fid: '{$folderid}'  id: '{$id}' )");
     // Parse the vcard
     $message = new SyncContact();
     try {
         // perform query and get feed of all results
         $query = new Zend_Gdata_Query(GCONTACTS_URL . '/' . $id);
         $entry = $this->service->getEntry($query);
     } catch (Zend_Gdata_App_Exception $e) {
         debugLog("GContacts::GetMessage - ERROR! (" . $e->getMessage() . ")");
         return false;
     }
     // parse feed and extract contact information
     // into simpler objects
     try {
         $doc = new DOMDocument();
         $doc->formatOutput = true;
         //$obj = new stdClass;
         //$obj->edit = $entry->getEditLink()->href;
         $xmldata = $entry->getXML();
         $doc->loadXML($xmldata);
         //filter out real contact id without other garbage
         preg_match("/[_a-z0-9]+\$/", $entry->id, $matches);
         $contactid = $matches[0];
         $fh = fopen(STATE_DIR . '/xml-get/' . (string) $entry->title . '_' . (string) $contactid . '.xml', 'w');
         fwrite($fh, $doc->saveXML());
         $xml = simplexml_load_string($xmldata);
         fclose($fh);
         //Prefix:
         //givenName:	 ok
         //Middle:
         //familyName:		ok
         //nameSuffix:	ok
         //last
         //first
         //middlename
         //title
         //suffix
         if (!empty($xml->name->fullName)) {
             debugLog('GContacts::GetMessage - fullName: ' . (string) $xml->name->fullName);
             $message->fileas = w2ui($xml->name->fullName);
         }
         //    if (!empty($xml->name->namePrefix)){
         //	debugLog('GContacts::GetMessage - namePrefix: '.(string) $xml->name->namePrefix);
         //	$message->middlename = w2ui($xml->name->namePrefix);
         //    }
         if (!empty($xml->name->givenName)) {
             debugLog('GContacts::GetMessage - givenName: ' . (string) $xml->name->givenName);
             $message->firstname = w2ui($xml->name->givenName);
         }
         //if (!empty($xml->name->????)){
         //	debugLog('GContacts::GetMessage - familyName: '.(string) $xml->name->????);
         //	$message->title = w2ui($xml->name->^^^^);
         //    }
         if (!empty($xml->name->familyName)) {
             debugLog('GContacts::GetMessage - familyName: ' . (string) $xml->name->familyName);
             $message->lastname = w2ui($xml->name->familyName);
         }
         if (!empty($xml->name->nameSuffix)) {
             debugLog('GContacts::GetMessage - nameSuffix: ' . (string) $xml->name->nameSuffix);
             $message->suffix = w2ui($xml->name->nameSuffix);
         }
         if (!empty($xml->organization->orgName)) {
             debugLog('GContacts::GetMessage - orgName: ' . (string) $xml->organization->orgName);
             $message->companyname = w2ui($xml->organization->orgName);
         }
         if (!empty($xml->organization->orgTitle)) {
             debugLog('GContacts::GetMessage - orgName: ' . (string) $xml->organization->orgTitle);
             $message->jobtitle = w2ui($xml->organization->orgTitle);
         }
         if (!empty($xml->nickname)) {
             debugLog('GContacts::GetMessage - Nickname: ' . (string) $xml->nickname);
             $message->nickname = w2ui($xml->nickname);
         }
         foreach ($xml->email as $e) {
             debugLog('GContacts::GetMessage - email: ' . (string) $e['address']);
             if (empty($message->email1address)) {
                 $message->email1address = w2ui($e['address']);
             } elseif (empty($message->email2address)) {
                 $message->email2address = w2ui($e['address']);
             } elseif (empty($message->email3address)) {
                 $message->email3address = w2ui($e['address']);
             } else {
                 debugLog('GContacts::GetMessage - LOST email address: ' . (string) $e['address']);
             }
         }
         foreach ($xml->im as $i) {
             debugLog('GContacts::GetMessage - im: ' . (string) $i['address']);
             if (empty($message->imaddress)) {
                 $message->imaddress = w2ui($i['address']);
             } elseif (empty($message->im2address)) {
                 $message->imaddress2 = w2ui($i['address']);
             } elseif (empty($message->imaddress3)) {
                 $message->imaddress3 = w2ui($i['address']);
             } else {
                 debugLog('GContacts::GetMessage - LOST im address: ' . (string) $i['address']);
             }
         }
         foreach ($xml->structuredPostalAddress as $p) {
             switch ($p['key']) {
                 case 'Children':
                     debugLog($p['key'] . ': ' . (string) $p['value']);
                     $message->children = w2ui($p['value']);
                     break;
                 case 'Spouse':
                     debugLog($p['key'] . ': ' . (string) $p['value']);
                     $message->spouse = w2ui($p['value']);
                     break;
             }
         }
         foreach ($xml->structuredPostalAddress as $p) {
             preg_match("/[_a-z0-9]+\$/", $p['rel'], $matches);
             $rel = $matches[0];
             switch ($rel) {
                 case 'home':
                     $a = 'home';
                     break;
                 case 'work':
                     break;
                 case 'office':
                     $a = 'business';
                     break;
                 case 'other':
                     $a = 'other';
                     break;
                 default:
                     debugLog('GContacts::GetMessage - structuredPostalAddress di tipo ' . $rel . ': non censito');
                     break;
             }
             if (!empty($p->street)) {
                 $b = $a . 'street';
                 debugLog($b . ': ' . (string) $p->street);
                 $message->{$b} = w2ui($p->street);
             }
             if (!empty($p->city)) {
                 $b = $a . 'city';
                 debugLog($b . ': ' . (string) $p->city);
                 $message->{$b} = w2ui($p->city);
             }
             if (!empty($p->postcode)) {
                 $b = $a . 'postalcode';
                 debugLog($b . ': ' . (string) $p->postcode);
                 $message->{$b} = w2ui($p->postcode);
             }
             if (!empty($p->region)) {
                 $b = $a . 'state';
                 debugLog($b . ': ' . (string) $p->region);
                 $message->{$b} = w2ui($p->region);
             }
             if (!empty($p->country)) {
                 $b = $a . 'country';
                 debugLog($b . ': ' . (string) $p->country);
                 $message->{$b} = w2ui($p->country);
             }
         }
         foreach ($xml->phoneNumber as $p) {
             preg_match("/[_a-z0-9]+\$/", $p['rel'], $matches);
             $rel = $matches[0];
             switch ($rel) {
                 case 'home':
                     if (empty($message->homephonenumber)) {
                         debugLog('GContacts::GetMessage - homephonenumber: ' . (string) $p);
                         $message->homephonenumber = w2ui($p);
                     } elseif (empty($message->home2phonenumber)) {
                         debugLog('GContacts::GetMessage - home2phonenumber: ' . (string) $p);
                         $message->home2phonenumber = w2ui($p);
                     } else {
                         debugLog('GContacts::GetMessage - LOST phone number: ' . (string) $p);
                     }
                     break;
                 case 'home_fax':
                     if (empty($message->homefaxnumber)) {
                         debugLog('GContacts::GetMessage - homefaxnumber: ' . (string) $p);
                         $message->homefaxnumber = w2ui($p);
                     } else {
                         debugLog('GContacts::GetMessage - LOST phone number: ' . (string) $p);
                     }
                     break;
                 case 'work_fax':
                     if (empty($message->businessfaxnumber)) {
                         debugLog('GContacts::GetMessage - businessfaxnumber: ' . (string) $p);
                         $message->businessfaxnumber = w2ui($p);
                     } else {
                         debugLog('GContacts::GetMessage - LOST phone number: ' . (string) $p);
                     }
                     break;
                 case 'mobile':
                     if (empty($message->mobilephonenumber)) {
                         debugLog('GContacts::GetMessage - mobilephonenumber: ' . (string) $p);
                         $message->mobilephonenumber = w2ui($p);
                     } elseif (empty($message->home2phonenumber)) {
                         debugLog('GContacts::GetMessage - home2phonenumber: ' . (string) $p);
                         $message->home2phonenumber = w2ui($p);
                     } elseif (empty($message->radiophonenumber)) {
                         debugLog('GContacts::GetMessage - radiophonenumber: ' . (string) $p);
                         $message->radiophonenumber = w2ui($p);
                     } else {
                         debugLog('GContacts::GetMessage - LOST phone number: ' . (string) $p);
                     }
                     break;
                 case 'work':
                     if (empty($message->businessphonenumber)) {
                         debugLog('GContacts::GetMessage - businessphonenumber: ' . (string) $p);
                         $message->businessphonenumber = w2ui($p);
                     } elseif (empty($message->business2phonenumber)) {
                         debugLog('GContacts::GetMessage - business2phonenumber: ' . (string) $p);
                         $message->business2phonenumber = w2ui($p);
                     } else {
                         debugLog('GContacts::GetMessage - LOST phone number: ' . (string) $p);
                     }
                     break;
                 case 'pager':
                     if (empty($message->pagernumber)) {
                         debugLog('GContacts::GetMessage - pagernumber: ' . (string) $p);
                         $message->pagernumber = w2ui($p);
                     } else {
                         debugLog('GContacts::GetMessage - LOST phone number: ' . (string) $p);
                     }
                     break;
                 case 'main':
                 case 'other':
                     if (empty($message->homephonenumber)) {
                         debugLog('GContacts::GetMessage - homephonenumber: ' . (string) $p);
                         $message->homephonenumber = w2ui($p);
                     } elseif (empty($message->home2phonenumber)) {
                         debugLog('GContacts::GetMessage - home2phonenumber: ' . (string) $p);
                         $message->home2phonenumber = w2ui($p);
                     } elseif (empty($message->businessphonenumber)) {
                         debugLog('GContacts::GetMessage - businessphonenumber: ' . (string) $p);
                         $message->businessphonenumber = w2ui($p);
                     } elseif (empty($message->business2phonenumber)) {
                         debugLog('GContacts::GetMessage - business2phonenumber: ' . (string) $p);
                         $message->business2phonenumber = w2ui($p);
                     } elseif (empty($message->carphonenumber)) {
                         debugLog('GContacts::GetMessage - carphonenumber: ' . (string) $p);
                         $message->carphonenumber = w2ui($p);
                     } else {
                         debugLog('GContacts::GetMessage - LOST phone number: ' . (string) $p);
                     }
                     break;
                 default:
                     debugLog('GContacts::GetMessage - LOST phone number: ' . (string) $p . ' phoneNumber di tipo ' . $rel . ': non censito');
                     break;
             }
         }
         if (!empty($xml->birthday['when'])) {
             debugLog('GContacts::GetMessage - birthday: ' . (string) $xml->birthday['when']);
             $tz = date_default_timezone_get();
             date_default_timezone_set('UTC');
             $message->birthday = strtotime($xml->birthday['when']);
             date_default_timezone_set($tz);
         }
         foreach ($xml->website as $w) {
             debugLog('GContacts::GetMessage - webpage: ' . (string) $w['href']);
             $message->webpage = w2ui($w['href']);
         }
         //$e["id"] = (string)$contactid;
         //$e["flags"] = "1";
         //$e["mod"] = strtotime((string)$entry->getUpdated());
         //$results[] = $e;
         //debugLog((string)$entry->getUpdated());
         if (!empty($entry->content)) {
             debugLog('GContacts::GetMessage - Note: ' . (string) $entry->content);
             if ($bodypreference === false) {
                 $message->body = w2ui($entry->content);
                 $message->bodysize = strlen($entry->content);
                 $message->bodytruncated = 0;
             } else {
                 if (isset($bodypreference[1]) && !isset($bodypreference[1]["TruncationSize"])) {
                     $bodypreference[1]["TruncationSize"] = 1024 * 1024;
                 }
                 if (isset($bodypreference[2]) && !isset($bodypreference[2]["TruncationSize"])) {
                     $bodypreference[2]["TruncationSize"] = 1024 * 1024;
                 }
                 if (isset($bodypreference[3]) && !isset($bodypreference[3]["TruncationSize"])) {
                     $bodypreference[3]["TruncationSize"] = 1024 * 1024;
                 }
                 if (isset($bodypreference[4]) && !isset($bodypreference[4]["TruncationSize"])) {
                     $bodypreference[4]["TruncationSize"] = 1024 * 1024;
                 }
                 $message->airsyncbasebody = new SyncAirSyncBaseBody();
                 debugLog("airsyncbasebody!");
                 $body = "";
                 $plain = $entry->content;
                 if (isset($bodypreference[2])) {
                     debugLog("HTML Body");
                     // Send HTML if requested and native type was html
                     $message->airsyncbasebody->type = 2;
                     $html = '<html>' . '<head>' . '<meta name="Generator" content="Z-Push">' . '<meta http-equiv="Content-Type" content="text/html; charset=utf-8">' . '</head>' . '<body>' . str_replace("\n", "<BR>", str_replace("\r", "<BR>", str_replace("\r\n", "<BR>", w2u($plain)))) . '</body>' . '</html>';
                     if (isset($bodypreference[2]["TruncationSize"]) && strlen($html) > $bodypreference[2]["TruncationSize"]) {
                         $html = utf8_truncate($html, $bodypreference[2]["TruncationSize"]);
                         $message->airsyncbasebody->truncated = 1;
                     }
                     $message->airsyncbasebody->data = $html;
                     $message->airsyncbasebody->estimateddatasize = strlen($html);
                 } else {
                     // Send Plaintext as Fallback or if original body is plaintext
                     debugLog("Plaintext Body");
                     $plain = $entry->content;
                     $plain = w2u(str_replace("\n", "\r\n", str_replace("\r", "", $plain)));
                     $message->airsyncbasebody->type = 1;
                     if (isset($bodypreference[1]["TruncationSize"]) && strlen($plain) > $bodypreference[1]["TruncationSize"]) {
                         $plain = utf8_truncate($plain, $bodypreference[1]["TruncationSize"]);
                         $message->airsyncbasebody->truncated = 1;
                     }
                     $message->airsyncbasebody->estimateddatasize = strlen($plain);
                     $message->airsyncbasebody->data = $plain;
                 }
                 // In case we have nothing for the body, send at least a blank...
                 // dw2412 but only in case the body is not rtf!
                 if ($message->airsyncbasebody->type != 3 && (!isset($message->airsyncbasebody->data) || strlen($message->airsyncbasebody->data) == 0)) {
                     $message->airsyncbasebody->data = " ";
                 }
             }
         }
         if (!empty($vcard['categories'][0]['val'])) {
             $message->categories = $vcard['categories'][0]['val'];
         }
         if (!empty($vcard['photo'][0]['val'][0])) {
             $message->picture = base64_encode($vcard['photo'][0]['val'][0]);
         }
     } catch (Exception $e) {
         debugLog('Gcontacts::GetMessageList - Problem retrieving data (' . $e->exception() . ')');
         return false;
     }
     return $message;
     /*
     $types = array ('dom' => 'type', 'intl' => 'type', 'postal' => 'type', 'parcel' => 'type', 'home' => 'type', 'work' => 'type',
         'pref' => 'type', 'voice' => 'type', 'fax' => 'type', 'msg' => 'type', 'cell' => 'type', 'pager' => 'type',
         'bbs' => 'type', 'modem' => 'type', 'car' => 'type', 'isdn' => 'type', 'video' => 'type',
         'aol' => 'type', 'applelink' => 'type', 'attmail' => 'type', 'cis' => 'type', 'eworld' => 'type',
         'internet' => 'type', 'ibmmail' => 'type', 'mcimail' => 'type',
         'powershare' => 'type', 'prodigy' => 'type', 'tlx' => 'type', 'x400' => 'type',
         'gif' => 'type', 'cgm' => 'type', 'wmf' => 'type', 'bmp' => 'type', 'met' => 'type', 'pmb' => 'type', 'dib' => 'type',
         'pict' => 'type', 'tiff' => 'type', 'pdf' => 'type', 'ps' => 'type', 'jpeg' => 'type', 'qtime' => 'type',
         'mpeg' => 'type', 'mpeg2' => 'type', 'avi' => 'type',
         'wave' => 'type', 'aiff' => 'type', 'pcm' => 'type',
         'x509' => 'type', 'pgp' => 'type', 'text' => 'value', 'inline' => 'value', 'url' => 'value', 'cid' => 'value', 'content-id' => 'value',
         '7bit' => 'encoding', '8bit' => 'encoding', 'quoted-printable' => 'encoding', 'base64' => 'encoding',
     );
     
     
     // Parse the vcard
     $message = new SyncContact();
     
     $data = file_get_contents($this->_path . "/" . $this->_items[$id]);
     $data = str_replace("\x00", '', $data);
     $data = str_replace("\r\n", "\n", $data);
     $data = str_replace("\r", "\n", $data);
     $data = preg_replace('/(\n)([ \t])/i', '', $data);
     
     $lines = explode("\n", $data);
     
     $vcard = array();
     foreach($lines as $line) {
         if (trim($line) == '')
     	continue;
         $pos = strpos($line, ':');
         if ($pos === false)
     	continue;
     
         $field = trim(substr($line, 0, $pos));
         $value = trim(substr($line, $pos+1));
     
         $fieldparts = preg_split('/(?<!\\\\)(\;)/i', $field, -1, PREG_SPLIT_NO_EMPTY);
     
         $type = strtolower(array_shift($fieldparts));
     
         $fieldvalue = array();
     
         foreach ($fieldparts as $fieldpart) {
     	if(preg_match('/([^=]+)=(.+)/', $fieldpart, $matches)){
     	    if(!in_array(strtolower($matches[1]),array('value','type','encoding','language')))
     		continue;
     	    if(isset($fieldvalue[strtolower($matches[1])]) && is_array($fieldvalue[strtolower($matches[1])])){
     		$fieldvalue[strtolower($matches[1])] = array_merge($fieldvalue[strtolower($matches[1])], preg_split('/(?<!\\\\)(\,)/i', $matches[2], -1, PREG_SPLIT_NO_EMPTY));
     	    }else{
     		$fieldvalue[strtolower($matches[1])] = preg_split('/(?<!\\\\)(\,)/i', $matches[2], -1, PREG_SPLIT_NO_EMPTY);
     	    }
     	}else{
     	    if(!isset($types[strtolower($fieldpart)]))
     		continue;
     	    $fieldvalue[$types[strtolower($fieldpart)]][] = $fieldpart;
     	}
         }
         //
         switch ($type) {
     	case 'categories':
     	    //case 'nickname':
     	    $val = preg_split('/(?<!\\\\)(\,)/i', $value);
     	    $val = array_map("w2ui", $val);
     	    break;
     	default:
     	    $val = preg_split('/(?<!\\\\)(\;)/i', $value);
     	    break;
         }
         if(isset($fieldvalue['encoding'][0])){
     	switch(strtolower($fieldvalue['encoding'][0])){
     	    case 'q':
     	    case 'quoted-printable':
     		foreach($val as $i => $v){
     		    $val[$i] = quoted_printable_decode($v);
     		}
     		break;
     	    case 'b':
     	    case 'base64':
     		foreach($val as $i => $v){
     		    $val[$i] = base64_decode($v);
     		}
     		break;
     	}
         }else{
     	foreach($val as $i => $v){
     	    $val[$i] = $this->unescape($v);
     	}
         }
         $fieldvalue['val'] = $val;
         $vcard[$type][] = $fieldvalue;
     }
     */
     /*
     	if(isset($vcard['tel'])){
     	    foreach($vcard['tel'] as $tel) {
     		if(!isset($tel['type'])){
     		    $tel['type'] = array();
     		}
     		if(in_array('car', $tel['type'])){
     		    $message->carphonenumber = $tel['val'][0];
     		}elseif(in_array('pager', $tel['type'])){
     		    $message->pagernumber = $tel['val'][0];
     		}elseif(in_array('cell', $tel['type'])){
     		    $message->mobilephonenumber = $tel['val'][0];
     		}elseif(in_array('home', $tel['type'])){
     		    if(in_array('fax', $tel['type'])){
     			$message->homefaxnumber = $tel['val'][0];
     		    }elseif(empty($message->homephonenumber)){
     			$message->homephonenumber = $tel['val'][0];
     		    }else{
     			$message->home2phonenumber = $tel['val'][0];
     		    }
     		}elseif(in_array('work', $tel['type'])){
     		    if(in_array('fax', $tel['type'])){
     			$message->businessfaxnumber = $tel['val'][0];
     		    }elseif(empty($message->businessphonenumber)){
     			$message->businessphonenumber = $tel['val'][0];
     		    }else{
     			$message->business2phonenumber = $tel['val'][0];
     		    }
     		}elseif(empty($message->homephonenumber)){
     		    $message->homephonenumber = $tel['val'][0];
     		}elseif(empty($message->home2phonenumber)){
     		    $message->home2phonenumber = $tel['val'][0];
     		}else{
     		    $message->radiophonenumber = $tel['val'][0];
     		}
     	    }
     	}
     */
     if (!empty($vcard['categories'][0]['val'])) {
         $message->categories = $vcard['categories'][0]['val'];
     }
     if (!empty($vcard['photo'][0]['val'][0])) {
         $message->picture = base64_encode($vcard['photo'][0]['val'][0]);
     }
     return $message;
 }
Esempio n. 19
0
 function GetMessage($folderid, $id, $truncsize, $bodypreference = false, $optionbodypreference = false, $mimesupport = 0)
 {
     debugLog('iCalDir::GetMessage(' . $folderid . ', ' . $this->_items[$id] . ', ..)');
     if ($folderid != "root") {
         return;
     }
     $types = array('dom' => 'type', 'intl' => 'type', 'postal' => 'type', 'parcel' => 'type', 'home' => 'type', 'work' => 'type', 'pref' => 'type', 'voice' => 'type', 'fax' => 'type', 'msg' => 'type', 'cell' => 'type', 'pager' => 'type', 'bbs' => 'type', 'modem' => 'type', 'car' => 'type', 'isdn' => 'type', 'video' => 'type', 'aol' => 'type', 'applelink' => 'type', 'attmail' => 'type', 'cis' => 'type', 'eworld' => 'type', 'internet' => 'type', 'ibmmail' => 'type', 'mcimail' => 'type', 'powershare' => 'type', 'prodigy' => 'type', 'tlx' => 'type', 'x400' => 'type', 'gif' => 'type', 'cgm' => 'type', 'wmf' => 'type', 'bmp' => 'type', 'met' => 'type', 'pmb' => 'type', 'dib' => 'type', 'pict' => 'type', 'tiff' => 'type', 'pdf' => 'type', 'ps' => 'type', 'jpeg' => 'type', 'qtime' => 'type', 'mpeg' => 'type', 'mpeg2' => 'type', 'avi' => 'type', 'wave' => 'type', 'aiff' => 'type', 'pcm' => 'type', 'x509' => 'type', 'pgp' => 'type', 'text' => 'value', 'inline' => 'value', 'url' => 'value', 'cid' => 'value', 'content-id' => 'value', '7bit' => 'encoding', '8bit' => 'encoding', 'quoted-printable' => 'encoding', 'base64' => 'encoding', 'uid' => 'value');
     // Parse the vcard
     $message = new SyncAppointment();
     $data = file_get_contents($this->_path . "/" . $this->_items[$id]);
     $data = str_replace("", '', $data);
     $data = str_replace("\r\n", "\n", $data);
     $data = str_replace("\r", "\n", $data);
     $data = preg_replace('/(\\n)([ \\t])/i', '', $data);
     $data = utf8_decode($data);
     $lines = explode("\n", $data);
     $vcard = array();
     foreach ($lines as $line) {
         if (trim($line) == '') {
             continue;
         }
         $pos = strpos($line, ':');
         if ($pos === false) {
             continue;
         }
         $field = trim(substr($line, 0, $pos));
         $value = trim(substr($line, $pos + 1));
         $fieldparts = preg_split('/(?<!\\\\)(\\;)/i', $field, -1, PREG_SPLIT_NO_EMPTY);
         $type = strtolower(array_shift($fieldparts));
         $fieldvalue = array();
         foreach ($fieldparts as $fieldpart) {
             if (preg_match('/([^=]+)=(.+)/', $fieldpart, $matches)) {
                 if (!in_array(strtolower($matches[1]), array('value', 'type', 'encoding', 'language'))) {
                     continue;
                 }
                 if (isset($fieldvalue[strtolower($matches[1])]) && is_array($fieldvalue[strtolower($matches[1])])) {
                     $fieldvalue[strtolower($matches[1])] = array_merge($fieldvalue[strtolower($matches[1])], preg_split('/(?<!\\\\)(\\,)/i', $matches[2], -1, PREG_SPLIT_NO_EMPTY));
                 } else {
                     $fieldvalue[strtolower($matches[1])] = preg_split('/(?<!\\\\)(\\,)/i', $matches[2], -1, PREG_SPLIT_NO_EMPTY);
                 }
             } else {
                 if (!isset($types[strtolower($fieldpart)])) {
                     continue;
                 }
                 $fieldvalue[$types[strtolower($fieldpart)]][] = $fieldpart;
             }
         }
         //
         switch ($type) {
             case 'categories':
                 //case 'nickname':
                 $val = preg_split('/(?<!\\\\)(\\,)/i', $value);
                 $val = array_map("w2ui", $val);
                 break;
             default:
                 $val = preg_split('/(?<!\\\\)(\\;)/i', $value);
                 break;
         }
         if (isset($fieldvalue['encoding'][0])) {
             switch (strtolower($fieldvalue['encoding'][0])) {
                 case 'q':
                 case 'quoted-printable':
                     foreach ($val as $i => $v) {
                         $val[$i] = quoted_printable_decode($v);
                     }
                     break;
                 case 'b':
                 case 'base64':
                     foreach ($val as $i => $v) {
                         $val[$i] = base64_decode($v);
                     }
                     break;
             }
         } else {
             foreach ($val as $i => $v) {
                 $val[$i] = $this->unescape($v);
             }
         }
         $fieldvalue['val'] = $val;
         $vcard[$type][] = $fieldvalue;
     }
     // debugLog('iCalDir::LoadedMessage-source:' . print_r($vcard,1));
     //http://www.zachstronaut.com/posts/2009/02/09/careful-with-php-empty.html
     // We pass all times in GMT to device. Calculation to gmt takes place based on timezone definition in config.php
     $message->timezone = base64_encode($this->_getSyncBlobFromTZ(array("bias" => 0, "dstendmonth" => 0, "dstendday" => 0, "dstendweek" => 0, "dstendhour" => 0, "dstendminute" => 0, "dstendsecond" => 0, "dstendmillis" => 0, "stdbias" => 0, "dststartmonth" => 0, "dststartday" => 0, "dststartweek" => 0, "dststarthour" => 0, "dststartminute" => 0, "dststartsecond" => 0, "dststartmillis" => 0, "dstbias" => 0)));
     $fieldmapping = $this->_mapping;
     foreach ($fieldmapping as $k => $v) {
         switch ($v) {
             // these fields should be filled with 0
             case 'busystatus':
             case 'sensitivity':
             case 'meetingstatus':
             case 'alldayevent':
                 $message->{$fieldmapping}[$k] = !empty($vcard[$k][0]['val'][0]) ? w2u($vcard[$k][0]['val'][0]) : "0";
                 break;
             case 'starttime':
             case 'endtime':
             case 'dtstamp':
                 if (empty($vcard[$k][0]['val'][0])) {
                     $message->{$fieldmapping}[$k] = NULL;
                     break;
                 }
                 $time = w2u($vcard[$k][0]['val'][0]);
                 $time = gmmktime(gmdate("H", $time), gmdate("i", $time), gmdate("s", $time), gmdate("n", $time), gmdate("j", $time), gmdate("Y", $time));
                 $message->{$fieldmapping}[$k] = $time;
                 break;
             case 'body':
                 if ($bodypreference == false) {
                     $message->body = w2u(str_replace("\n", "\r\n", str_replace("\r", "", $vcard[$k][0]['val'][0])));
                     $message->bodysize = strlen($message->body);
                     $message->bodytruncated = 0;
                 } else {
                     $message->airsyncbasebody = new SyncAirSyncBaseBody();
                     debugLog("airsyncbasebody!");
                     $message->airsyncbasenativebodytype = 1;
                     if (isset($bodypreference[2])) {
                         debugLog("HTML Body");
                         // Send HTML if requested and native type was html
                         $message->airsyncbasebody->type = 2;
                         $html = '<html>' . '<head>' . '<meta name="Generator" content="Z-Push">' . '<meta http-equiv="Content-Type" content="text/html; charset=utf-8">' . '</head>' . '<body>' . str_replace("\n", "<BR>", str_replace("\r", "<BR>", str_replace("\r\n", "<BR>", w2u($vcard[$k][0]['val'][0])))) . '</body>' . '</html>';
                         if (isset($bodypreference[2]["TruncationSize"]) && strlen($html) > $bodypreference[2]["TruncationSize"]) {
                             $html = utf8_truncate($html, $bodypreference[2]["TruncationSize"]);
                             $message->airsyncbasebody->truncated = 1;
                         }
                         $message->airsyncbasebody->data = $html;
                         $message->airsyncbasebody->estimateddatasize = strlen($html);
                     } else {
                         // Send Plaintext as Fallback or if original body is plaintext
                         debugLog("Plaintext Body");
                         $plain = w2u(str_replace("\n", "\r\n", str_replace("\r", "", $vcard[$k][0]['val'][0])));
                         $message->airsyncbasebody->type = 1;
                         if (isset($bodypreference[1]["TruncationSize"]) && strlen($plain) > $bodypreference[1]["TruncationSize"]) {
                             $plain = utf8_truncate($plain, $bodypreference[1]["TruncationSize"]);
                             $message->airsyncbasebody->truncated = 1;
                         }
                         $message->airsyncbasebody->estimateddatasize = strlen($plain);
                         $message->airsyncbasebody->data = $plain;
                     }
                     // In case we have nothing for the body, send at least a blank...
                     // dw2412 but only in case the body is not rtf!
                     if ($message->airsyncbasebody->type != 3 && (!isset($message->airsyncbasebody->data) || strlen($message->airsyncbasebody->data) == 0)) {
                         $message->airsyncbasebody->data = " ";
                     }
                 }
                 break;
             default:
                 $vs = explode("->", $v);
                 if ($vs[0] == "recurrence" && !empty($vcard[$k][0]['val'][0])) {
                     if (!isset($message->recurrence)) {
                         $message->recurrence = new SyncRecurrence();
                     }
                     $message->recurrence->{$vs}[1] = !empty($vcard[$k][0]['val'][0]) ? w2u($vcard[$k][0]['val'][0]) : NULL;
                 } else {
                     $message->{$fieldmapping}[$k] = !empty($vcard[$k][0]['val'][0]) ? w2u($vcard[$k][0]['val'][0]) : NULL;
                 }
         }
     }
     if (!isset($message->uid) || strlen($message->uid) == 0) {
         $message->uid = $this->_uid();
     }
     if (isset($message->recurrence)) {
         if (!isset($message->recurrence->interval)) {
             debugLog('iCalDir::GetMessage: Error, recurrence object found but no interval is set. Set it to 1 since it needs to be set');
             $message->recurrence->interval = 1;
         }
     }
     // debugLog('iCalDir::LoadedMessage-imported:' . print_r($message,1));
     return $message;
 }
Esempio n. 20
0
 function _getEmail($mapimessage, $truncsize, $mimesupport = 0)
 {
     $message = new SyncMail();
     $this->_getPropsFromMAPI($message, $mapimessage, $this->_emailmapping);
     // Override 'From' to show "Full Name <*****@*****.**>"
     $messageprops = mapi_getprops($mapimessage, array(PR_SENT_REPRESENTING_NAME, PR_SENT_REPRESENTING_ENTRYID, PR_SOURCE_KEY));
     // Override 'body' for truncation
     $body = mapi_openproperty($mapimessage, PR_BODY);
     $message->bodysize = strlen($body);
     if ($message->bodysize > $truncsize) {
         $body = utf8_truncate($body, $truncsize);
         $message->bodytruncated = 1;
     } else {
         $message->bodytruncated = 0;
     }
     $message->body = str_replace("\n", "\r\n", w2u(str_replace("\r", "", $body)));
     if (isset($messageprops[PR_SOURCE_KEY])) {
         $sourcekey = $messageprops[PR_SOURCE_KEY];
     } else {
         return false;
     }
     $fromname = $fromaddr = "";
     if (isset($messageprops[PR_SENT_REPRESENTING_NAME])) {
         $fromname = $messageprops[PR_SENT_REPRESENTING_NAME];
     }
     if (isset($messageprops[PR_SENT_REPRESENTING_ENTRYID])) {
         $fromaddr = $this->_getSMTPAddressFromEntryID($messageprops[PR_SENT_REPRESENTING_ENTRYID]);
     }
     if ($fromname == $fromaddr) {
         $fromname = "";
     }
     if ($fromname) {
         $from = "\"" . w2u($fromname) . "\" <" . w2u($fromaddr) . ">";
     } else {
         //START CHANGED dw2412 HTC shows "error" if sender name is unknown
         $from = "\"" . w2u($fromaddr) . "\" <" . w2u($fromaddr) . ">";
     }
     //END CHANGED dw2412 HTC shows "error" if sender name is unknown
     $message->from = $from;
     // process Meeting Requests
     if (isset($message->messageclass) && strpos($message->messageclass, "IPM.Schedule.Meeting") === 0) {
         $message->meetingrequest = new SyncMeetingRequest();
         $this->_getPropsFromMAPI($message->meetingrequest, $mapimessage, $this->_meetingrequestmapping);
         $goidtag = $this->_getPropIdFromString("PT_BINARY:{6ED8DA90-450B-101B-98DA-00AA003F1305}:0x3");
         $timezonetag = $this->_getPropIDFromString("PT_BINARY:{00062002-0000-0000-C000-000000000046}:0x8233");
         $recReplTime = $this->_getPropIDFromString("PT_SYSTIME:{00062002-0000-0000-C000-000000000046}:0x8228");
         $isrecurringtag = $this->_getPropIDFromString("PT_BOOLEAN:{00062002-0000-0000-C000-000000000046}:0x8223");
         $recurringstate = $this->_getPropIDFromString("PT_BINARY:{00062002-0000-0000-C000-000000000046}:0x8216");
         $appSeqNr = $this->_getPropIDFromString("PT_LONG:{00062002-0000-0000-C000-000000000046}:0x8201");
         $lidIsException = $this->_getPropIDFromString("PT_BOOLEAN:{00062002-0000-0000-C000-000000000046}:0xA");
         $recurStartTime = $this->_getPropIDFromString("PT_LONG:{6ED8DA90-450B-101B-98DA-00AA003F1305}:0xE");
         $recurrenceend = $this->_getPropIDFromString("PT_SYSTIME:{00062002-0000-0000-C000-000000000046}:0x8236");
         $props = mapi_getprops($mapimessage, array($goidtag, $timezonetag, $recReplTime, $isrecurringtag, $recurringstate, $appSeqNr, $lidIsException, $recurStartTime, $recurrenceend));
         // Get the GOID
         if (isset($props[$goidtag])) {
             $message->meetingrequest->globalobjid = base64_encode($props[$goidtag]);
         }
         // Set Timezone
         if (isset($props[$timezonetag])) {
             $tz = $this->_getTZFromMAPIBlob($props[$timezonetag]);
         } else {
             $tz = $this->_getGMTTZ();
         }
         $message->meetingrequest->timezone = base64_encode($this->_getSyncBlobFromTZ($tz));
         // send basedate if exception
         if (isset($props[$recReplTime]) || isset($props[$lidIsException]) && $props[$lidIsException] == true) {
             if (isset($props[$recReplTime])) {
                 $basedate = $props[$recReplTime];
                 $message->meetingrequest->recurrenceid = $this->_getGMTTimeByTZ($basedate, $this->_getGMTTZ());
             } else {
                 if (!isset($props[$goidtag]) || !isset($props[$recurStartTime]) || !isset($props[$timezonetag])) {
                     debugLog("Missing property to set correct basedate for exception");
                 } else {
                     $basedate = extractBaseDate($props[$goidtag], $props[$recurStartTime]);
                     $message->meetingrequest->recurrenceid = $this->_getGMTTimeByTZ($basedate, $tz);
                 }
             }
         }
         // Organizer is the sender
         $message->meetingrequest->organizer = $message->from;
         // Process recurrence
         if (isset($props[$isrecurringtag]) && $props[$isrecurringtag]) {
             $myrec = new SyncMeetingRequestRecurrence();
             // get recurrence -> put $message->meetingrequest as message so the 'alldayevent' is set correctly
             $this->_getRecurrence($mapimessage, $props, $message->meetingrequest, $myrec, $tz);
             $message->meetingrequest->recurrences = array($myrec);
         }
         // Force the 'alldayevent' in the object at all times. (non-existent == 0)
         if (!isset($message->meetingrequest->alldayevent) || $message->meetingrequest->alldayevent == "") {
             $message->meetingrequest->alldayevent = 0;
         }
         // Instancetype
         // 0 = single appointment
         // 1 = master recurring appointment
         // 2 = single instance of recurring appointment
         // 3 = exception of recurring appointment
         $message->meetingrequest->instancetype = 0;
         if (isset($props[$isrecurringtag]) && $props[$isrecurringtag] == 1) {
             $message->meetingrequest->instancetype = 1;
         } else {
             if ((!isset($props[$isrecurringtag]) || $props[$isrecurringtag] == 0) && isset($message->meetingrequest->recurrenceid)) {
                 if (isset($props[$appSeqNr]) && $props[$appSeqNr] == 0) {
                     $message->meetingrequest->instancetype = 2;
                 } else {
                     $message->meetingrequest->instancetype = 3;
                 }
             }
         }
         // Disable reminder if it is off
         $reminderset = $this->_getPropIDFromString("PT_BOOLEAN:{00062008-0000-0000-C000-000000000046}:0x8503");
         $remindertime = $this->_getPropIDFromString("PT_LONG:{00062008-0000-0000-C000-000000000046}:0x8501");
         $messageprops = mapi_getprops($mapimessage, array($reminderset, $remindertime));
         if (!isset($messageprops[$reminderset]) || $messageprops[$reminderset] == false) {
             $message->meetingrequest->reminder = "";
         } else {
             ///set the default reminder time to seconds
             if ($messageprops[$remindertime] == 0x5ae980e1) {
                 $message->meetingrequest->reminder = 900;
             } else {
                 $message->meetingrequest->reminder = $messageprops[$remindertime] * 60;
             }
         }
         // Set sensitivity to 0 if missing
         if (!isset($message->meetingrequest->sensitivity)) {
             $message->meetingrequest->sensitivity = 0;
         }
     }
     // Add attachments
     $attachtable = mapi_message_getattachmenttable($mapimessage);
     $rows = mapi_table_queryallrows($attachtable, array(PR_ATTACH_NUM));
     foreach ($rows as $row) {
         if (isset($row[PR_ATTACH_NUM])) {
             $mapiattach = mapi_message_openattach($mapimessage, $row[PR_ATTACH_NUM]);
             $attachprops = mapi_getprops($mapiattach, array(PR_ATTACH_LONG_FILENAME, PR_ATTACH_FILENAME));
             $attach = new SyncAttachment();
             $stream = mapi_openpropertytostream($mapiattach, PR_ATTACH_DATA_BIN);
             if ($stream) {
                 $stat = mapi_stream_stat($stream);
                 $attach->attsize = $stat["cb"];
                 $attach->displayname = w2u(isset($attachprops[PR_ATTACH_LONG_FILENAME]) ? $attachprops[PR_ATTACH_LONG_FILENAME] : (isset($attachprops[PR_ATTACH_FILENAME]) ? $attachprops[PR_ATTACH_FILENAME] : "attachment.bin"));
                 $attach->attname = bin2hex($this->_folderid) . ":" . bin2hex($sourcekey) . ":" . $row[PR_ATTACH_NUM];
                 if (!isset($message->attachments)) {
                     $message->attachments = array();
                 }
                 array_push($message->attachments, $attach);
             }
         }
     }
     // Get To/Cc as SMTP addresses (this is different from displayto and displaycc because we are putting
     // in the SMTP addresses as well, while displayto and displaycc could just contain the display names
     $to = array();
     $cc = array();
     $reciptable = mapi_message_getrecipienttable($mapimessage);
     $rows = mapi_table_queryallrows($reciptable, array(PR_RECIPIENT_TYPE, PR_DISPLAY_NAME, PR_ADDRTYPE, PR_EMAIL_ADDRESS, PR_SMTP_ADDRESS));
     foreach ($rows as $row) {
         $address = "";
         $fulladdr = "";
         $addrtype = isset($row[PR_ADDRTYPE]) ? $row[PR_ADDRTYPE] : "";
         if (isset($row[PR_SMTP_ADDRESS])) {
             $address = $row[PR_SMTP_ADDRESS];
         } else {
             if ($addrtype == "SMTP" && isset($row[PR_EMAIL_ADDRESS])) {
                 $address = $row[PR_EMAIL_ADDRESS];
             }
         }
         $name = isset($row[PR_DISPLAY_NAME]) ? $row[PR_DISPLAY_NAME] : "";
         if ($name == "" || $name == $address) {
             $fulladdr = w2u($address);
         } else {
             if (substr($name, 0, 1) != '"' && substr($name, -1) != '"') {
                 $fulladdr = "\"" . w2u($name) . "\" <" . w2u($address) . ">";
             } else {
                 $fulladdr = w2u($name) . "<" . w2u($address) . ">";
             }
         }
         if ($row[PR_RECIPIENT_TYPE] == MAPI_TO) {
             array_push($to, $fulladdr);
         } else {
             if ($row[PR_RECIPIENT_TYPE] == MAPI_CC) {
                 array_push($cc, $fulladdr);
             }
         }
     }
     $message->to = implode(", ", $to);
     $message->cc = implode(", ", $cc);
     if (!isset($message->body) || strlen($message->body) == 0) {
         $message->body = " ";
     }
     if ($mimesupport == 2 && function_exists("mapi_inetmapi_imtoinet")) {
         $addrBook = mapi_openaddressbook($this->_session);
         $mstream = mapi_inetmapi_imtoinet($this->_session, $addrBook, $mapimessage, array());
         $mstreamstat = mapi_stream_stat($mstream);
         if ($mstreamstat['cb'] < MAX_EMBEDDED_SIZE) {
             $message->mimetruncated = 0;
             $mstreamcontent = mapi_stream_read($mstream, MAX_EMBEDDED_SIZE);
             $message->mimedata = $mstreamcontent;
             $message->mimesize = $mstreamstat["cb"];
             unset($message->body, $message->bodytruncated);
         }
     }
     // without importance some mobiles assume "0" (low) - Mantis #439
     if (!isset($message->importance)) {
         $message->importance = 1;
     }
     return $message;
 }
Esempio n. 21
0
 public function confirm($order_id, $order_status_id, $comment = '', $notify = false)
 {
     $order_info = $this->getOrder($order_id);
     if ($order_info && !$order_info['order_status_id']) {
         $this->db->query("UPDATE `" . DB_PREFIX . "order` SET order_status_id = '" . (int) $order_status_id . "', date_modified = NOW() WHERE order_id = '" . (int) $order_id . "'");
         $this->db->query("INSERT INTO " . DB_PREFIX . "order_history SET order_id = '" . (int) $order_id . "', order_status_id = '" . (int) $order_status_id . "', notify = '1', comment = '" . $this->db->escape($comment && $notify ? $comment : '') . "', date_added = NOW()");
         $order_product_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_product WHERE order_id = '" . (int) $order_id . "'");
         foreach ($order_product_query->rows as $order_product) {
             $this->db->query("UPDATE " . DB_PREFIX . "product SET quantity = (quantity - " . (int) $order_product['quantity'] . ") WHERE product_id = '" . (int) $order_product['product_id'] . "' AND subtract = '1'");
             $order_option_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_option WHERE order_id = '" . (int) $order_id . "' AND order_product_id = '" . (int) $order_product['order_product_id'] . "'");
             foreach ($order_option_query->rows as $option) {
                 $this->db->query("UPDATE " . DB_PREFIX . "product_option_value SET quantity = (quantity - " . (int) $order_product['quantity'] . ") WHERE product_option_value_id = '" . (int) $option['product_option_value_id'] . "' AND subtract = '1'");
             }
         }
         $this->cache->delete('product');
         $order_total_query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "order_total` WHERE order_id = '" . (int) $order_id . "'");
         foreach ($order_total_query->rows as $order_total) {
             $this->load->model('total/' . $order_total['code']);
             if (method_exists($this->{'model_total_' . $order_total['code']}, 'confirm')) {
                 $this->{'model_total_' . $order_total['code']}->confirm($order_info, $order_total);
             }
         }
         // Send out any gift voucher mails
         if ($this->config->get('config_complete_status_id') == $order_status_id) {
             $this->load->model('checkout/voucher');
             $this->model_checkout_voucher->confirm($order_id);
         }
         // Send out order confirmation mail
         $language = new Language($order_info['language_directory']);
         $language->load($order_info['language_filename']);
         $language->load('mail/order');
         $order_status_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_status WHERE order_status_id = '" . (int) $order_status_id . "' AND language_id = '" . (int) $order_info['language_id'] . "'");
         if ($order_status_query->num_rows) {
             $order_status = $order_status_query->row['name'];
         } else {
             $order_status = '';
         }
         $order_product_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_product WHERE order_id = '" . (int) $order_id . "'");
         $order_total_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_total WHERE order_id = '" . (int) $order_id . "' ORDER BY sort_order ASC");
         $order_download_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_download WHERE order_id = '" . (int) $order_id . "'");
         $subject = sprintf($language->get('text_new_subject'), $order_info['store_name'], $order_id);
         // HTML Mail
         $template = new Template();
         $template->data['title'] = sprintf($language->get('text_new_subject'), html_entity_decode($order_info['store_name'], ENT_QUOTES, 'UTF-8'), $order_id);
         $template->data['text_greeting'] = sprintf($language->get('text_new_greeting'), html_entity_decode($order_info['store_name'], ENT_QUOTES, 'UTF-8'));
         $template->data['text_link'] = $language->get('text_new_link');
         $template->data['text_download'] = $language->get('text_new_download');
         $template->data['text_order_detail'] = $language->get('text_new_order_detail');
         $template->data['text_instruction'] = $language->get('text_new_instruction');
         $template->data['text_order_id'] = $language->get('text_new_order_id');
         $template->data['text_date_added'] = $language->get('text_new_date_added');
         $template->data['text_payment_method'] = $language->get('text_new_payment_method');
         $template->data['text_shipping_method'] = $language->get('text_new_shipping_method');
         $template->data['text_email'] = $language->get('text_new_email');
         $template->data['text_telephone'] = $language->get('text_new_telephone');
         $template->data['text_ip'] = $language->get('text_new_ip');
         $template->data['text_payment_address'] = $language->get('text_new_payment_address');
         $template->data['text_shipping_address'] = $language->get('text_new_shipping_address');
         $template->data['text_product'] = $language->get('text_new_product');
         $template->data['text_model'] = $language->get('text_new_model');
         $template->data['text_quantity'] = $language->get('text_new_quantity');
         $template->data['text_price'] = $language->get('text_new_price');
         $template->data['text_total'] = $language->get('text_new_total');
         $template->data['text_footer'] = $language->get('text_new_footer');
         $template->data['text_powered'] = $language->get('text_new_powered');
         $template->data['logo'] = 'cid:' . md5(basename($this->config->get('config_logo')));
         $template->data['store_name'] = $order_info['store_name'];
         $template->data['store_url'] = $order_info['store_url'];
         $template->data['customer_id'] = $order_info['customer_id'];
         $template->data['link'] = $order_info['store_url'] . 'index.php?route=account/order/info&order_id=' . $order_id;
         if ($order_download_query->num_rows) {
             $template->data['download'] = $order_info['store_url'] . 'index.php?route=account/download';
         } else {
             $template->data['download'] = '';
         }
         $template->data['order_id'] = $order_id;
         $template->data['date_added'] = date($language->get('date_format_short'), strtotime($order_info['date_added']));
         $template->data['payment_method'] = $order_info['payment_method'];
         $template->data['shipping_method'] = $order_info['shipping_method'];
         $template->data['email'] = $order_info['email'];
         $template->data['telephone'] = $order_info['telephone'];
         $template->data['ip'] = $order_info['ip'];
         if ($comment && $notify) {
             $template->data['comment'] = nl2br($comment);
         } else {
             $template->data['comment'] = '';
         }
         if ($order_info['shipping_address_format']) {
             $format = $order_info['shipping_address_format'];
         } else {
             $format = '{firstname} {lastname}' . "\n" . '{company}' . "\n" . '{address_1}' . "\n" . '{address_2}' . "\n" . '{city} {postcode}' . "\n" . '{zone}' . "\n" . '{country}';
         }
         $find = array('{firstname}', '{lastname}', '{company}', '{address_1}', '{address_2}', '{city}', '{postcode}', '{zone}', '{zone_code}', '{country}');
         $replace = array('firstname' => $order_info['shipping_firstname'], 'lastname' => $order_info['shipping_lastname'], 'company' => $order_info['shipping_company'], 'address_1' => $order_info['shipping_address_1'], 'address_2' => $order_info['shipping_address_2'], 'city' => $order_info['shipping_city'], 'postcode' => $order_info['shipping_postcode'], 'zone' => $order_info['shipping_zone'], 'zone_code' => $order_info['shipping_zone_code'], 'country' => $order_info['shipping_country']);
         $template->data['shipping_address'] = str_replace(array("\r\n", "\r", "\n"), '<br />', preg_replace(array("/\\s\\s+/", "/\r\r+/", "/\n\n+/"), '<br />', trim(str_replace($find, $replace, $format))));
         if ($order_info['payment_address_format']) {
             $format = $order_info['payment_address_format'];
         } else {
             $format = '{firstname} {lastname}' . "\n" . '{company}' . "\n" . '{address_1}' . "\n" . '{address_2}' . "\n" . '{city} {postcode}' . "\n" . '{zone}' . "\n" . '{country}';
         }
         $find = array('{firstname}', '{lastname}', '{company}', '{address_1}', '{address_2}', '{city}', '{postcode}', '{zone}', '{zone_code}', '{country}');
         $replace = array('firstname' => $order_info['payment_firstname'], 'lastname' => $order_info['payment_lastname'], 'company' => $order_info['payment_company'], 'address_1' => $order_info['payment_address_1'], 'address_2' => $order_info['payment_address_2'], 'city' => $order_info['payment_city'], 'postcode' => $order_info['payment_postcode'], 'zone' => $order_info['payment_zone'], 'zone_code' => $order_info['payment_zone_code'], 'country' => $order_info['payment_country']);
         $template->data['payment_address'] = str_replace(array("\r\n", "\r", "\n"), '<br />', preg_replace(array("/\\s\\s+/", "/\r\r+/", "/\n\n+/"), '<br />', trim(str_replace($find, $replace, $format))));
         $template->data['products'] = array();
         foreach ($order_product_query->rows as $product) {
             $option_data = array();
             $order_option_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_option WHERE order_id = '" . (int) $order_id . "' AND order_product_id = '" . (int) $product['order_product_id'] . "'");
             foreach ($order_option_query->rows as $option) {
                 if ($option['type'] != 'file') {
                     $option_data[] = array('name' => $option['name'], 'value' => utf8_truncate($option['value']));
                 } else {
                     $filename = substr($option['value'], 0, strrpos($option['value'], '.'));
                     $option_data[] = array('name' => $option['name'], 'value' => utf8_truncate($filename));
                 }
             }
             $template->data['products'][] = array('name' => $product['name'], 'model' => $product['model'], 'option' => $option_data, 'quantity' => $product['quantity'], 'price' => $this->currency->format($product['price'], $order_info['currency_code'], $order_info['currency_value']), 'total' => $this->currency->format($product['total'], $order_info['currency_code'], $order_info['currency_value']));
         }
         $template->data['totals'] = $order_total_query->rows;
         if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/mail/order.tpl')) {
             $html = $template->fetch($this->config->get('config_template') . '/template/mail/order.tpl');
         } else {
             $html = $template->fetch('default/template/mail/order.tpl');
         }
         // Text Mail
         $text = sprintf($language->get('text_new_greeting'), html_entity_decode($order_info['store_name'], ENT_QUOTES, 'UTF-8')) . "\n\n";
         $text .= $language->get('text_new_order_id') . ' ' . $order_id . "\n";
         $text .= $language->get('text_new_date_added') . ' ' . date($language->get('date_format_short'), strtotime($order_info['date_added'])) . "\n";
         $text .= $language->get('text_new_order_status') . ' ' . $order_status . "\n\n";
         if ($comment && $notify) {
             $text .= $language->get('text_new_instruction') . "\n\n";
             $text .= $comment . "\n\n";
         }
         $text .= $language->get('text_new_products') . "\n";
         foreach ($order_product_query->rows as $result) {
             $text .= $result['quantity'] . 'x ' . $result['name'] . ' (' . $result['model'] . ') ' . html_entity_decode($this->currency->format($result['total'], $order_info['currency_code'], $order_info['currency_value']), ENT_NOQUOTES, 'UTF-8') . "\n";
             $order_option_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_option WHERE order_id = '" . (int) $order_id . "' AND order_product_id = '" . $result['order_product_id'] . "'");
             foreach ($order_option_query->rows as $option) {
                 $text .= chr(9) . '-' . $option['name'] . ' ' . utf8_truncate($option['value']) . "\n";
             }
         }
         $text .= "\n";
         $text .= $language->get('text_new_order_total') . "\n";
         foreach ($order_total_query->rows as $result) {
             $text .= $result['title'] . ' ' . html_entity_decode($result['text'], ENT_NOQUOTES, 'UTF-8') . "\n";
         }
         $text .= "\n";
         if ($order_info['customer_id']) {
             $text .= $language->get('text_new_link') . "\n";
             $text .= $order_info['store_url'] . 'index.php?route=account/order/info&order_id=' . $order_id . "\n\n";
         }
         if ($order_download_query->num_rows) {
             $text .= $language->get('text_new_download') . "\n";
             $text .= $order_info['store_url'] . 'index.php?route=account/download' . "\n\n";
         }
         if ($order_info['comment']) {
             $text .= $language->get('text_new_comment') . "\n\n";
             $text .= $order_info['comment'] . "\n\n";
         }
         $text .= $language->get('text_new_footer') . "\n\n";
         $mail = new Mail();
         $mail->protocol = $this->config->get('config_mail_protocol');
         $mail->parameter = $this->config->get('config_mail_parameter');
         $mail->hostname = $this->config->get('config_smtp_host');
         $mail->username = $this->config->get('config_smtp_username');
         $mail->password = $this->config->get('config_smtp_password');
         $mail->port = $this->config->get('config_smtp_port');
         $mail->timeout = $this->config->get('config_smtp_timeout');
         $mail->setTo($order_info['email']);
         $mail->setFrom($this->config->get('config_email'));
         $mail->setSender($order_info['store_name']);
         $mail->setSubject($subject);
         $mail->setHtml($html);
         $mail->setText(html_entity_decode($text, ENT_QUOTES, 'UTF-8'));
         $mail->addAttachment(DIR_IMAGE . $this->config->get('config_logo'), md5(basename($this->config->get('config_logo'))));
         $mail->send();
         // Admin Alert Mail
         if ($this->config->get('config_alert_mail')) {
             $subject = sprintf($language->get('text_new_subject'), html_entity_decode($this->config->get('config_name'), ENT_QUOTES, 'UTF-8'), $order_id);
             // Text
             $text = $language->get('text_new_received') . "\n\n";
             $text .= $language->get('text_new_order_id') . ' ' . $order_id . "\n";
             $text .= $language->get('text_new_date_added') . ' ' . date($language->get('date_format_short'), strtotime($order_info['date_added'])) . "\n";
             $text .= $language->get('text_new_order_status') . ' ' . $order_status . "\n\n";
             $text .= $language->get('text_new_products') . "\n";
             foreach ($order_product_query->rows as $result) {
                 $text .= $result['quantity'] . 'x ' . $result['name'] . ' (' . $result['model'] . ') ' . html_entity_decode($this->currency->format($result['total'], $order_info['currency_code'], $order_info['currency_value']), ENT_NOQUOTES, 'UTF-8') . "\n";
                 $order_option_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_option WHERE order_id = '" . (int) $order_id . "' AND order_product_id = '" . $result['order_product_id'] . "'");
                 foreach ($order_option_query->rows as $option) {
                     $text .= chr(9) . '-' . $option['name'] . ' ' . utf8_truncate($option['value']) . "\n";
                 }
             }
             $text .= "\n";
             $text .= $language->get('text_new_order_total') . "\n";
             foreach ($order_total_query->rows as $result) {
                 $text .= $result['title'] . ' ' . html_entity_decode($result['text'], ENT_NOQUOTES, 'UTF-8') . "\n";
             }
             $text .= "\n";
             if ($order_info['comment'] != '') {
                 $comment = $order_info['comment'] . "\n\n" . $comment;
             }
             if ($comment) {
                 $text .= $language->get('text_new_comment') . "\n\n";
                 $text .= $comment . "\n\n";
             }
             $mail = new Mail();
             $mail->protocol = $this->config->get('config_mail_protocol');
             $mail->parameter = $this->config->get('config_mail_parameter');
             $mail->hostname = $this->config->get('config_smtp_host');
             $mail->username = $this->config->get('config_smtp_username');
             $mail->password = $this->config->get('config_smtp_password');
             $mail->port = $this->config->get('config_smtp_port');
             $mail->timeout = $this->config->get('config_smtp_timeout');
             $mail->setTo($this->config->get('config_email'));
             $mail->setFrom($this->config->get('config_email'));
             $mail->setSender($order_info['store_name']);
             $mail->setSubject($subject);
             $mail->setText($text);
             $mail->send();
             // Send to additional alert emails
             $emails = explode(',', $this->config->get('config_alert_emails'));
             foreach ($emails as $email) {
                 if ($email && preg_match('/^[^\\@]+@.*\\.[a-z]{2,6}$/i', $email)) {
                     $mail->setTo($email);
                     $mail->send();
                 }
             }
         }
         // Send Admins SMS if configure
         if ($this->config->get('config_sms_alert')) {
             $options = array('to' => $this->config->get('config_sms_to'), 'copy' => $this->config->get('config_sms_copy'), 'from' => $this->config->get('config_sms_from'), 'username' => $this->config->get('config_sms_gate_username'), 'password' => $this->config->get('config_sms_gate_password'), 'message' => str_replace(array('{ID}', '{DATE}', '{TIME}', '{SUM}', '{PHONE}'), array($order_id, date('d.m.Y'), date('H:i'), floatval($order_info['total']), $order_info['telephone']), $this->config->get('config_sms_message')));
             $this->load->library('sms');
             $sms = new Sms($this->config->get('config_sms_gatename'), $options);
             $sms->send();
         }
     }
 }
Esempio n. 22
0
 public function index()
 {
     $this->language->load('product/special');
     $this->load->model('catalog/product');
     $this->load->model('tool/image');
     if (isset($this->request->get['sort'])) {
         $sort = $this->request->get['sort'];
     } else {
         $sort = 'p.sort_order';
     }
     if (isset($this->request->get['order'])) {
         $order = $this->request->get['order'];
     } else {
         $order = 'ASC';
     }
     if (isset($this->request->get['page'])) {
         $page = $this->request->get['page'];
     } else {
         $page = 1;
     }
     if (isset($this->request->get['limit'])) {
         $limit = $this->request->get['limit'];
     } else {
         $limit = $this->config->get('config_catalog_limit');
     }
     $this->document->setTitle($this->language->get('heading_title'));
     $this->data['breadcrumbs'] = array();
     $this->data['breadcrumbs'][] = array('text' => $this->language->get('text_home'), 'href' => $this->url->link('common/home'), 'separator' => false);
     $url = '';
     if (isset($this->request->get['sort'])) {
         $url .= '&sort=' . $this->request->get['sort'];
     }
     if (isset($this->request->get['order'])) {
         $url .= '&order=' . $this->request->get['order'];
     }
     if (isset($this->request->get['page'])) {
         $url .= '&page=' . $this->request->get['page'];
     }
     if (isset($this->request->get['limit'])) {
         $url .= '&limit=' . $this->request->get['limit'];
     }
     $this->data['breadcrumbs'][] = array('text' => $this->language->get('heading_title'), 'href' => $this->url->link('product/special', $url), 'separator' => $this->language->get('text_separator'));
     $this->data['heading_title'] = $this->language->get('heading_title');
     $this->data['text_empty'] = $this->language->get('text_empty');
     $this->data['text_quantity'] = $this->language->get('text_quantity');
     $this->data['text_manufacturer'] = $this->language->get('text_manufacturer');
     $this->data['text_model'] = $this->language->get('text_model');
     $this->data['text_price'] = $this->language->get('text_price');
     $this->data['text_tax'] = $this->language->get('text_tax');
     $this->data['text_points'] = $this->language->get('text_points');
     $this->data['text_compare'] = sprintf($this->language->get('text_compare'), isset($this->session->data['compare']) ? count($this->session->data['compare']) : 0);
     $this->data['text_display'] = $this->language->get('text_display');
     $this->data['text_list'] = $this->language->get('text_list');
     $this->data['text_grid'] = $this->language->get('text_grid');
     $this->data['text_sort'] = $this->language->get('text_sort');
     $this->data['text_limit'] = $this->language->get('text_limit');
     $this->data['button_cart'] = $this->language->get('button_cart');
     $this->data['button_wishlist'] = $this->language->get('button_wishlist');
     $this->data['button_compare'] = $this->language->get('button_compare');
     $this->data['compare'] = $this->url->link('product/compare');
     $this->data['products'] = array();
     $data = array('sort' => $sort, 'order' => $order, 'start' => ($page - 1) * $limit, 'limit' => $limit);
     $product_total = $this->model_catalog_product->getTotalProductSpecials($data);
     $results = $this->model_catalog_product->getProductSpecials($data);
     foreach ($results as $result) {
         if ($result['image']) {
             $image = $this->model_tool_image->resize($result['image'], $this->config->get('config_image_product_width'), $this->config->get('config_image_product_height'));
         } else {
             $image = false;
         }
         if ($this->config->get('config_customer_price') && $this->customer->isLogged() || !$this->config->get('config_customer_price')) {
             $price = $this->currency->format($this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax')));
         } else {
             $price = false;
         }
         if ((double) $result['special']) {
             $special = $this->currency->format($this->tax->calculate($result['special'], $result['tax_class_id'], $this->config->get('config_tax')));
         } else {
             $special = false;
         }
         if ($this->config->get('config_tax')) {
             $tax = $this->currency->format((double) $result['special'] ? $result['special'] : $result['price']);
         } else {
             $tax = false;
         }
         if ($this->config->get('config_review_status')) {
             $rating = (int) $result['rating'];
         } else {
             $rating = false;
         }
         $this->data['products'][] = array('product_id' => $result['product_id'], 'thumb' => $image, 'name' => $result['name'], 'description' => utf8_truncate(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8')), 400, '&nbsp;&hellip;', true), 'price' => $price, 'special' => $special, 'tax' => $tax, 'rating' => $result['rating'], 'reviews' => sprintf($this->language->get('text_reviews'), (int) $result['reviews']), 'href' => $this->url->link('product/product', $url . '&product_id=' . $result['product_id']));
     }
     $url = '';
     if (isset($this->request->get['limit'])) {
         $url .= '&limit=' . $this->request->get['limit'];
     }
     $this->data['sorts'] = array();
     $this->data['sorts'][] = array('text' => $this->language->get('text_default'), 'value' => 'p.sort_order-ASC', 'href' => $this->url->link('product/special', 'sort=p.sort_order&order=ASC' . $url));
     $this->data['sorts'][] = array('text' => $this->language->get('text_name_asc'), 'value' => 'pd.name-ASC', 'href' => $this->url->link('product/special', 'sort=pd.name&order=ASC' . $url));
     $this->data['sorts'][] = array('text' => $this->language->get('text_name_desc'), 'value' => 'pd.name-DESC', 'href' => $this->url->link('product/special', 'sort=pd.name&order=DESC' . $url));
     $this->data['sorts'][] = array('text' => $this->language->get('text_price_asc'), 'value' => 'ps.price-ASC', 'href' => $this->url->link('product/special', 'sort=ps.price&order=ASC' . $url));
     $this->data['sorts'][] = array('text' => $this->language->get('text_price_desc'), 'value' => 'special-DESC', 'href' => $this->url->link('product/special', 'sort=special&order=DESC' . $url));
     $this->data['sorts'][] = array('text' => $this->language->get('text_rating_desc'), 'value' => 'rating-DESC', 'href' => $this->url->link('product/special', 'sort=rating&order=DESC' . $url));
     $this->data['sorts'][] = array('text' => $this->language->get('text_rating_asc'), 'value' => 'rating-ASC', 'href' => $this->url->link('product/special', 'sort=rating&order=ASC' . $url));
     $this->data['sorts'][] = array('text' => $this->language->get('text_model_asc'), 'value' => 'p.model-ASC', 'href' => $this->url->link('product/special', 'sort=p.model&order=ASC' . $url));
     $this->data['sorts'][] = array('text' => $this->language->get('text_model_desc'), 'value' => 'p.model-DESC', 'href' => $this->url->link('product/special', 'sort=p.model&order=DESC' . $url));
     $url = '';
     if (isset($this->request->get['sort'])) {
         $url .= '&sort=' . $this->request->get['sort'];
     }
     if (isset($this->request->get['order'])) {
         $url .= '&order=' . $this->request->get['order'];
     }
     $this->data['limits'] = array();
     $this->data['limits'][] = array('text' => $this->config->get('config_catalog_limit'), 'value' => $this->config->get('config_catalog_limit'), 'href' => $this->url->link('product/special', $url . '&limit=' . $this->config->get('config_catalog_limit')));
     $this->data['limits'][] = array('text' => 25, 'value' => 25, 'href' => $this->url->link('product/special', $url . '&limit=25'));
     $this->data['limits'][] = array('text' => 50, 'value' => 50, 'href' => $this->url->link('product/special', $url . '&limit=50'));
     $this->data['limits'][] = array('text' => 75, 'value' => 75, 'href' => $this->url->link('product/special', $url . '&limit=75'));
     $this->data['limits'][] = array('text' => 100, 'value' => 100, 'href' => $this->url->link('product/special', $url . '&limit=100'));
     $url = '';
     if (isset($this->request->get['sort'])) {
         $url .= '&sort=' . $this->request->get['sort'];
     }
     if (isset($this->request->get['order'])) {
         $url .= '&order=' . $this->request->get['order'];
     }
     if (isset($this->request->get['limit'])) {
         $url .= '&limit=' . $this->request->get['limit'];
     }
     $pagination = new Pagination();
     $pagination->total = $product_total;
     $pagination->page = $page;
     $pagination->limit = $limit;
     $pagination->text = $this->language->get('text_pagination');
     $pagination->url = $this->url->link('product/special', $url . '&page={page}');
     $this->data['pagination'] = $pagination->render();
     $this->data['sort'] = $sort;
     $this->data['order'] = $order;
     $this->data['limit'] = $limit;
     if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/product/special.tpl')) {
         $this->template = $this->config->get('config_template') . '/template/product/special.tpl';
     } else {
         $this->template = 'default/template/product/special.tpl';
     }
     $this->children = array('common/column_left', 'common/column_right', 'common/content_top', 'common/content_bottom', 'common/footer', 'common/header');
     $this->response->setOutput($this->render());
 }
Esempio n. 23
0
function truncate($content, $size = 50, $final = "…", $stripHTML = false, $preserveEOL = false)
{
    $hasn = false;
    if ($stripHTML) {
        $content = str_replace("\"", "'", stripHTML(str_replace("\n", "", $content), $preserveEOL));
        if ($preserveEOL) {
            $content = str_replace("<br/>", "\n", $content);
            $hasn = strpos($content, "\n") !== false;
        }
    }
    // avoids amp codes being cut
    $len = strlen($content);
    $amp = strpos($content, '&', $size - 5 >= 0 && $size - 5 < $len ? $size - 5 : 0);
    if ($amp > 0 && $amp <= $size) {
        $ampf = strpos($content, ';', $amp);
        if ($ampf >= $size) {
            return ($preserveEOL ? str_replace("\n", "<br/>", substr($content, 0, $amp - 1)) : substr($content, 0, $amp - 1)) . ($hasn ? "\n" : "") . $final;
        }
    }
    if ($len > $size) {
        if ($len <= $size - strlen($final)) {
            // barelly on the limit
            return ($preserveEOL ? str_replace("\n", "<br/>", $content) : $content) . $final;
        } else {
            // under the limit, cut utf8 to avoid issues
            return ($preserveEOL ? str_replace("\n", "<br/>", utf8_truncate($content, $size - strlen($final))) : utf8_truncate($content, $size - strlen($final))) . $final . " ";
        }
    } else {
        // not greater
        return ($preserveEOL ? str_replace("\n", "<br/>", $content) : $content) . "";
    }
}