root/contributed_modules/modules/bulkdids/functions.inc.php

Revision 8084, 4.1 kB (checked in by p_lindheimer, 3 years ago)

Auto Check-in of any outstanding patches

Line 
1 <?php
2 //This file is part of FreePBX.
3 //
4 //    FreePBX is free software: you can redistribute it and/or modify
5 //    it under the terms of the GNU General Public License as published by
6 //    the Free Software Foundation, either version 2 of the License, or
7 //    (at your option) any later version.
8 //
9 //    FreePBX is distributed in the hope that it will be useful,
10 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
11 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 //    GNU General Public License for more details.
13 //
14 //    You should have received a copy of the GNU General Public License
15 //    along with FreePBX.  If not, see <http://www.gnu.org/licenses/>.
16 //
17 //    Copyright 2006 Seth Sargent, Steven Ward
18 //    Portions Copyright 2009 Mikael Carlsson, mickecamino@gmail.com
19 //    Portions Copyright 2009 Schmooze Communications LLC
20 //
21 /* functions.inc.php - functions for BulkDIDs module. */
22
23 function exportdids_all() {
24   global $db;
25   $action   = "edit";
26   $fname    = "bulkdids__" .  (string) time() . $_SERVER["SERVER_NAME"] . ".csv";
27   $csv_header   = "action,DID,description,destination,cidnum,alertinfo,grppre,mohclass,ringing,privacyman\n";
28   $data     = $csv_header;
29   $exts     = get_all_dids();
30   foreach ($exts as $ext) {
31
32     $e  = $ext;
33     $did_info = core_did_get($e['extension'],$e['cidnum']);
34     $csv_line[0]  = $action;
35     $csv_line[1]  = isset($did_info["extension"])?$did_info["extension"]:"";
36     $csv_line[2]  = isset($did_info["description"])?$did_info["description"]:"";
37     $csv_line[3]  = isset($did_info["destination"])?$did_info["destination"]:"";
38     $csv_line[4]  = isset($did_info["cidnum"])?$did_info["cidnum"]:"";
39     $csv_line[5]  = isset($did_info["alertinfo"])?$did_info["alertinfo"]:"";
40     $csv_line[6]  = isset($did_info["grppre"])?$did_info["grppre"]:"";
41     $csv_line[7]  = isset($did_info["mohclass"])?$did_info["mohclass"]:"";
42     $csv_line[8]  = isset($did_info["ringing"])?$did_info["ringing"]:"0";
43     $csv_line[9]  = isset($did_info["privacyman"])?$did_info["privacyman"]:"";
44
45     for ($i = 0; $i < count($csv_line); $i++) {
46       /* If the string contains a comma, enclose it in double-quotes. */
47       if (strpos($csv_line[$i], ",") !== FALSE) {
48         $csv_line[$i] = "\"" . $csv_line[$i] . "\"";
49       }
50       if ($i != count($csv_line) - 1) {
51         $data = $data . $csv_line[$i] . ",";
52       } else {
53         $data = $data . $csv_line[$i];
54       }
55     }
56     $data = $data . "\n";
57     unset($csv_line);
58   }
59   bulkdids_force_download($data, $fname);
60   return;
61 }
62
63 function get_all_dids() {
64   $sql  = "SELECT extension,cidnum FROM incoming ORDER BY extension";
65   //$extens = sql($sql,"getAll");
66   $extens = sql($sql,"getAll",DB_FETCHMODE_ASSOC);
67   if (isset($extens)) {
68     return $extens;
69   } else {
70     return null;
71   }
72 }
73
74 function bulkdids_force_download ($data, $name, $mimetype="", $filesize=false) {
75     // File size not set?
76     if ($filesize == false OR !is_numeric($filesize)) {
77         $filesize = strlen($data);
78     }
79     // Mimetype not set?
80     if (empty($mimetype)) {
81         $mimetype = "application/octet-stream";
82     }
83     // Make sure there's not anything else left
84     bulkdids_ob_clean_all();
85     // Start sending headers
86     header("Pragma: public"); // required
87     header("Expires: 0");
88     header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
89     header("Cache-Control: private",false); // required for certain browsers
90     header("Content-Transfer-Encoding: binary");
91     header("Content-Type: " . $mimetype);
92     header("Content-Length: " . $filesize);
93     header("Content-Disposition: attachment; filename=\"" . $name . "\";" );
94     // Send data
95     echo $data;
96     die();
97 }
98
99 function bulkdids_ob_clean_all () {
100     $ob_active = ob_get_length () !== false;
101     while($ob_active) {
102         ob_end_clean();
103         $ob_active = ob_get_length () !== false;
104     }
105     return true;
106 }
107
108 function bulkdids_generate_table_rows() {
109   $fh = fopen("modules/bulkdids/table.csv", "r");
110   if ($fh == NULL) {
111     return NULL;
112   }
113   $k = 0;
114   while (($csv_data = fgetcsv($fh, 1000, ",", "\"")) !== FALSE) {
115     $k++;
116     for ($i = 0; $i < 5; $i++) {
117       if (isset($csv_data[$i])) {
118         $table[$k][$i] .= $csv_data[$i];
119       } else {
120         $table[$k][$i] = "";
121       }
122     }
123   }
124   fclose($fh);
125   return $table;
126 }
127 ?>
Note: See TracBrowser for help on using the browser.