Exemplo n.º 1
0
 $ListView = new ListView();
 $ListView->initNewXTemplate('modules/Campaigns/Schedule.html', $current_module_strings);
 if ($test) {
     $ListView->xTemplateAssign("SCHEDULE_MESSAGE_HEADER", $current_module_strings['LBL_SCHEDULE_MESSAGE_TEST']);
 } else {
     $ListView->xTemplateAssign("SCHEDULE_MESSAGE_HEADER", $current_module_strings['LBL_SCHEDULE_MESSAGE_EMAILS']);
 }
 //force multi-select popup
 $ListView->process_for_popups = true;
 $ListView->multi_select_popup = true;
 //end
 $ListView->mergeduplicates = false;
 $ListView->show_export_button = false;
 $ListView->show_select_menu = false;
 $ListView->show_delete_button = false;
 $ListView->setDisplayHeaderAndFooter(false);
 $ListView->xTemplateAssign("RETURN_MODULE", $_POST['return_module']);
 $ListView->xTemplateAssign("RETURN_ACTION", $_POST['return_action']);
 $ListView->xTemplateAssign("RETURN_ID", $_POST['record']);
 $ListView->setHeaderTitle($current_module_strings['LBL_LIST_FORM_TITLE']);
 $ListView->setQuery($where, "", "date_modified desc", "EMAILMARKETING", false);
 if ($test) {
     $ListView->xTemplateAssign("MODE", $_POST['mode']);
     //finds all marketing messages that have an association with prospect list of the test.
     //this query can be siplified using sub-selects.
     $query = "select distinct email_marketing.id email_marketing_id from email_marketing ";
     $query .= " inner join email_marketing_prospect_lists empl on empl.email_marketing_id = email_marketing.id ";
     $query .= " inner join prospect_lists on prospect_lists.id = empl.prospect_list_id ";
     $query .= " inner join prospect_list_campaigns plc on plc.prospect_list_id = empl.prospect_list_id ";
     $query .= " where empl.deleted=0  ";
     $query .= " and prospect_lists.deleted=0 ";
Exemplo n.º 2
0
 function execute($format = 'TABLE', $parameter_values = array())
 {
     global $sugar_config, $current_user, $current_language;
     global $beanList, $beanFiles;
     $beanName = $beanList[$this->mainmodule];
     $beanFile = $beanFiles[$beanName];
     if (!empty($beanName) && !empty($beanFile)) {
         require_once $beanFile;
         $seed = new $beanName();
         $filters = $this->get_filters();
         $sql_where = array();
         foreach ($filters as $filter) {
             $sql_where[] = $filter->create_where_clause($parameter_values);
         }
         $orders = $this->get_orders();
         $sql_order = array();
         foreach ($orders as $order) {
             $sql_order[] = $order->create_order_clause($parameter_values);
         }
         if ($this->filtertype == "AND") {
             $sql_join = " and ";
         } else {
             if ($this->filtertype == "OR") {
                 $sql_join = " or ";
             } else {
                 $sql_join = " and ";
             }
         }
         if (!empty($sql_join) && !empty($sql_where)) {
             $where_clause = "(" . join($sql_join, $sql_where) . ")";
         }
         if (!empty($sql_order)) {
             $order_clause = join(", ", $sql_order);
         }
         if (!empty($this->customwhere1)) {
             $where_clause = $this->customwhere1 . " " . $where_clause;
         }
         if (!empty($this->customwhere2)) {
             $where_clause = $where_clause . " " . $this->customwhere1;
         }
         $rows = $seed->get_full_list($order_clause, $where_clause);
         if (empty($rows)) {
             $rows = array();
         }
         $this->report_output .= "Found " . count($rows) . " rows<br/>";
         if ($format == "TABLE" || $format == "HTML" || $format == "SIMPLEHTML" || $format == "CSV") {
             $list_data = array();
             $list_fields = array();
             foreach ($rows as $row) {
                 $row_data = $row->get_list_view_data();
                 $row_data_mapped = array();
                 foreach (array_keys($row_data) as $key) {
                     $row_data_mapped[strtoupper($this->mainmodule) . "_" . $key] = $row_data[$key];
                 }
                 $list_data[] = new ListingRow($row_data_mapped);
                 if (empty($list_fields)) {
                     foreach (array_keys($row_data) as $key) {
                         $list_fields[] = $key;
                     }
                 }
             }
             if ($format == "HTML" || $format == "TABLE") {
                 if ($this->list_template == "default") {
                     require_once 'include/ListView/ListViewSmarty.php';
                     if (file_exists('custom/modules/' . $this->mainmodule . '/metadata/listviewdefs.php')) {
                         require_once 'custom/modules/' . $this->mainmodule . '/metadata/listviewdefs.php';
                     } else {
                         require_once 'modules/' . $this->mainmodule . '/metadata/listviewdefs.php';
                     }
                     $lv = new ListViewSmarty();
                     $displayColumns = array();
                     foreach ($listViewDefs[$this->mainmodule] as $col => $params) {
                         if (!empty($params['default']) && $params['default']) {
                             $displayColumns[$col] = $params;
                         }
                     }
                     $lv->displayColumns = $displayColumns;
                     $lv->setup($seed, 'include/ListView/ListViewGeneric.tpl', $where_clause, $params);
                     ob_start();
                     echo $lv->display();
                 } else {
                     require_once 'include/ListView/ListView.php';
                     $lv = new ListView();
                     if ($_REQUEST["is_scheduler"] = "true") {
                         $lv->setDisplayHeaderAndFooter(false);
                     }
                     $lv->initNewXTemplate('modules/ZuckerListingTemplate/lists/' . $this->list_template, return_module_language($current_language, $this->mainmodule));
                     $lv->xTemplateAssign("SITE_URL", $sugar_config["site_url"]);
                     ob_start();
                     $lv->processListViewTwo($list_data, "rows", "ROW");
                 }
                 if ($format == "HTML") {
                     $date = date("ymd_His");
                     $this->report_result_type = "FILE";
                     $this->report_result_name = $date . "_" . $this->name . ".html";
                     $this->report_result_name = strtolower(join("_", explode(" ", $this->report_result_name)));
                     $this->report_result = $this->archive_dir . "/" . $this->report_result_name;
                     $f = fopen($this->report_result, "w");
                     $c = file_get_contents("modules/ZuckerListingTemplate/lists/header.html");
                     $c = str_replace("{SITE_URL}", $sugar_config["site_url"], $c);
                     $c = str_replace("{THEME_URL}", $sugar_config["site_url"] . "/themes/" . $theme, $c);
                     fwrite($f, $c);
                     fwrite($f, ob_get_clean());
                     fwrite($f, file_get_contents("modules/ZuckerListingTemplate/lists/footer.html"));
                     fclose($f);
                 } else {
                     $this->report_result_type = "INLINE";
                     $this->report_result = ob_get_clean();
                 }
             } else {
                 if ($format == "SIMPLEHTML") {
                     $date = date("ymd_His");
                     $this->report_result_type = "FILE";
                     $this->report_result_name = $date . "_" . $this->name . ".html";
                     $this->report_result_name = strtolower(join("_", explode(" ", $this->report_result_name)));
                     $this->report_result = $this->archive_dir . "/" . $this->report_result_name;
                     $f = fopen($this->report_result, "w");
                     fwrite($f, "<!DOCTYPE html PUBLIC \"-//W3C//DTD html 4.01 Transitional//EN\">\n");
                     fwrite($f, "<html><body><table border=\"1\">");
                     if ($this->include_header && !empty($list_fields)) {
                         fwrite($f, "\n<tr>");
                         foreach ($list_fields as $col_name) {
                             fwrite($f, "<th>" . $col_name . "</th>");
                         }
                         fwrite($f, "</tr>");
                     }
                     foreach ($list_data as $list_row) {
                         fwrite($f, "\n<tr>");
                         foreach (array_keys($list_row->list_view_data) as $col_name) {
                             $field = $list_row->list_view_data[$col_name];
                             if (empty($field)) {
                                 fwrite($f, "<td>&nbsp;</td>");
                             } else {
                                 fwrite($f, "<td>" . $this->format_value_for_html($field) . "</td>");
                             }
                         }
                         fwrite($f, "</tr>");
                     }
                     fwrite($f, "\n</table></body></html>");
                     fclose($f);
                 } else {
                     if ($format == "CSV") {
                         $date = date("ymd_His");
                         $this->report_result_type = "FILE";
                         $this->report_result_name = $date . "_" . $this->name . ".csv";
                         $this->report_result_name = strtolower(join("_", explode(" ", $this->report_result_name)));
                         $this->report_result = $this->archive_dir . "/" . $this->report_result_name;
                         $f = fopen($this->report_result, "w");
                         if ($this->include_header && count($list_data) > 0) {
                             $row = $list_data[0];
                             foreach (array_keys($row->list_view_data) as $col_name) {
                                 fwrite($f, $col_name);
                                 fwrite($f, $this->col_delim);
                             }
                             fwrite($f, $this->row_delim);
                         }
                         foreach ($list_data as $list_row) {
                             foreach (array_keys($list_row->list_view_data) as $col_name) {
                                 $field = $list_row->list_view_data[$col_name];
                                 $pieces = explode("\n", $field);
                                 $cleaned_pieces = array();
                                 foreach ($pieces as $piece) {
                                     $cleaned_pieces[] = trim($piece);
                                 }
                                 fwrite($f, join(" ", $cleaned_pieces));
                                 if ($i != count($list_row->list_view_data) - 1) {
                                     fwrite($f, $this->col_delim);
                                 }
                             }
                             fwrite($f, $this->row_delim);
                         }
                         fclose($f);
                     }
                 }
             }
         } else {
             if ($format == "PROSPECTLIST") {
                 require_once "modules/ProspectLists/ProspectList.php";
                 $pl = new ProspectList();
                 $pl->name = empty($_REQUEST["prospect_list_name"]) ? $this->name : $_REQUEST["prospect_list_name"];
                 $pl->save();
                 foreach ($rows as $row) {
                     if ($row->object_name == "Contact") {
                         $pl->set_relationship('prospect_lists_prospects', array("related_type" => "Contacts", "related_id" => $row->id, 'prospect_list_id' => $pl->id));
                     } else {
                         if ($row->object_name == "Lead") {
                             $pl->set_relationship('prospect_lists_prospects', array("related_type" => "Leads", "related_id" => $row->id, 'prospect_list_id' => $pl->id));
                         } else {
                             if ($row->object_name == "Prospect") {
                                 $pl->set_relationship('prospect_lists_prospects', array("related_type" => "Prospects", "related_id" => $row->id, 'prospect_list_id' => $pl->id));
                             }
                         }
                     }
                 }
                 $this->report_result = "index.php?module=ProspectLists&action=DetailView&record=" . $pl->id;
                 $this->report_result_type = "FORWARD";
             }
         }
         $result = true;
     }
     return $result;
 }