s2doemails.php /// Art: Online Auftragsverwaltung /// Inhalt: Emails /// Beschreibung: Alle Funktionen zu Emails /// Benötigt: Alle, siehe init /// CCML-Parsing: notwendig /// ////////////////////////////////////////////////////////////////////////////////////////// /// /// Letzte Änderungen: /// 07.12.2008 Suchfunktion umgestellt /// 26.03.2009 Tracking URL absolut /// 31.07.2010 Anpassung Parameter Suche /// 05.08.2010 Prefix eingebaut /// 13.08.2010 expected_date formatieren /// ////////////////////////////////////////////////////////////////////////////////////////// ///<13.08.2010/7.0.1.13/> define('ROOT', './'); define('ASSETS', ROOT.'assets/'); require(ASSETS.'s2diconf.php'); require(CC_INCLUDE_INIT); if (!$session->is_shopadmin()) { $session->unset_client(); redirect(CC_URL_LOGIN); } require(CC_BLOGIC_CONFIG); require(CC_INCLUDE_OSFUNCTIONS); $config = new config('emails'); $config_search = new config('search'); //////////////////////////////////////////////////////////////////////////// // Template vorbereiten $template = new template(CC_TPL_OSEMAILS, true); $template->ressources(CC_INCLUDE_OSLANG); $template->show('emails'); $template->show('searchmenu'); $template->show('viewmenu'); $template->show('pagination'); myorder($config, array('date', 'order_id', 'client_id')); mydirection($config); myperpage($config, $template); mypage($config); $email = new email(); $count = $email->db_numrows(); $max_page = max(1, ceil($count / $config->perpage)); // Suche $mode = get(PARAMETER_MODE, CHECK_ALPHA_); $search = rawurldecode(get(PARAMETER_TEXT, CHECK_ALL)); if ($mode && $search) { switch($mode) { case 'order_id': $where = array('order_id' => $search); break; case 'client_id': $where = array('client_id' => $search); break; } $searching = true; $config->set('searchmode', $mode); $config->set('searchexpr', $search); $max_page = max(1, ceil($email->db_numrows($where) / $config->perpage)); } else { $where = array(); $searching = false; } pagination($config, $template, $max_page); // Emails einlesen while($e = $email->get(array('*'), $where, array($config->order.' '.$config->direction, "date $config->direction", "time $config->direction"), $config->page, $config->perpage)) $template->loop('email', array( 'formatteddate' => date(CC_SITE_DATEFORMAT, strtotime($e->date)), 'from' => $e->from_plain.($e->from_email ? ' ('.$e->from_email.')' : ''), 'to' => $e->to_plain.($e->to_email ? ' ('.$e->to_email.')' : ''), 'subject' => substr($e->subject, 0, 50).(strlen($e->subject) > 50 ? ' ...' : ''), 'account' => $e->client_id > 0 ? 1 : 0, ), $e); // Kundespezifische Email if ($c = get(PARAMETER_CLIENT, CHECK_NUM)) { $template->show('new'); $client = new client($c); $template->assign(array( '_client_id' => $client->client_id, '_to_plain' => rawurlencode($client->firstname.' '.$client->lastname), '_to_email' => $client->email, '_from_plain' => rawurlencode(CC_SITE_MAILNAME), '_from_email' => CC_SITE_MAILFROM, )); } // Auftragsspezifische Email if ($o = get(PARAMETER_ID, CHECK_NUM)) { $template->show('new'); $order = new order($o); $template->assign(array( '_client_id' => $order->client->client_id, '_order_id' => $order->order_id, '_to_plain' => rawurlencode($order->client->firstname.' '.$order->client->lastname), '_to_email' => $order->client->email, '_from_plain' => rawurlencode(CC_SITE_MAILNAME), '_from_email' => CC_SITE_MAILFROM, )); } // Vorlage laden und parsen if ($m = get(PARAMETER_VIEW, CHECK_NUM)) { // Template Variablen einlesen $active = false; foreach(file(CC_INCLUDE_OSTEMPLATES) as $line) { $line = trim($line); if (strlen($line)) { if ($active) { if (preg_match("/^\[.*\]$/", $line)) { if (!preg_match("/^\[Template-Variables-.*\]$/", $line)) $active = false; } else if (preg_match("/^([a-z_]+)=(.*)$/", $line, $found)) $mailtemplate_vars[$found[1]] = $found[2]; else if (!preg_match("/^;/", $line, $found)) die('Error in file '.CC_INCLUDE_OSTEMPLATES.', unknown command "'.$line.'".'); } else if (preg_match("/^\[Template-Variables-.*\]$/", $line)) $active = true; } } $mailtemplate = new abstractdb(TABLE_TEMPLATES, $m); // Vorlagenvariablen foreach ($mailtemplate_vars as $key => $var) { $orig[] = '/{'.$var.'}/'; if ($key == 'country') $repl[] = isset($order) ? substr($order->client->$key, 11) : substr($client->$key, 11); else if ($key == 'signature') $repl[] = str_replace('
', "\n", CC_SITE_SHOPADDRESS); else if (strstr($key, '_date')) $repl[] = isset($order) && $order->$key ? date(CC_SITE_DATEFORMAT, strtotime($order->$key)) : ''; else if (in_array($key, array('order_id', 'order_id_prefix', 'tracking_id', 'message', 'expected_date'))) $repl[] = isset($order) && $order->$key ? $order->$key : ''; else if ($key == 'shipping_trackingurl') $repl[] = CC_SITE_HTTPURL . clean_url($order->$key); else $repl[] = isset($order) ? $order->client->$key : $client->$key; } $body = preg_replace($orig, $repl, $mailtemplate->body); $template->assign(array( '_subject' => rawurlencode($mailtemplate->subject), '_body' => rawurlencode($body), )); } // Template befüllen und fertig if (get(PARAMETER_MODE, CHECK_ALPHA_) == 'new') $template->show('new'); if ($searching) $template->show('searching'); $template->assign(array( '_date' => date(CC_SITE_DATEFORMAT), '_headline1' => $template->vars['email'], '_emails_selected' => 'selected', '_selected_entry' => $config->selected, '_email_x' => $config->x, '_email_y' => $config->y, '_search_x' => $config_search->x, '_search_y' => $config_search->y, '_max_page' => $max_page, '_search_param' => $mode ? PARAMETER_MODE."=$mode&".PARAMETER_TEXT."=$search&" : '', '_search_mode' => $mode ? $mode : '', '_search_expr' => $search ? $search : '', '_search_expr_value' => $config->searchexpr, '_search_oid_checked' => $config->searchmode == 'order_id' ? 'checked="checked"' : '', '_search_cid_checked' => $config->searchmode == 'client_id' ? 'checked="checked"' : '', '_date_selected' => $config->order == 'date' ? 'selected="selected"' : '', '_orderid_selected' => $config->order == 'order_id' ? 'selected="selected"' : '', '_clientid_selected' => $config->order == 'client_id' ? 'selected="selected"' : '', '_desc_checked' => $config->direction == 'desc' ? 'checked="checked"' : '', )); $template->out(); ?>