Xataface Email Module  0.3.2
Email/Mailmerge Module for Xataface
 All Data Structures Files Functions Variables Pages
get_email_addresses.php
Go to the documentation of this file.
1 <?php
3  function handle(&$params){
4  $app =& Dataface_Application::getInstance();
5  $query = $app->getQuery();
6  $query['-skip'] = 0;
7  $query['-limit'] = 999999999;
8 
9  $at = Dataface_ActionTool::getInstance();
10  $emailAction = $at->getAction(array('name'=>'email'));
11  if ( $emailAction ){
12  import('Dataface/Ontology.php');
13  Dataface_Ontology::registerType('Person', 'Dataface/Ontology/Person.php', 'Dataface_Ontology_Person');
14  $ontology = Dataface_Ontology::newOntology('Person', $query['-table']);
15  //print_r($ontology->getFieldname('email'));exit;
16  $emailAction['email_column'] = $ontology->getFieldname('email');
17 
18  }
19  if ( !isset($emailAction) or !isset($emailAction['email_column']) ){
20  return PEAR::raiseError("No email column specified");
21  }
22 
23 
24  $col = $emailAction['email_column'];
25 
26  $qb = new Dataface_QueryBuilder($query['-table'], $query);
27  $sql = "select distinct (`".$col."`) `".$col."` ".$qb->_from().$qb->_secure($qb->_where());
28 
29  $res = mysql_query($sql, df_db());
30  if ( !$res ) trigger_error(mysql_error(df_db()), E_USER_ERROR);
31 
32  $addresses = array();
33  while ($row = mysql_fetch_row($res) ) $addresses[] = $row[0];
34  @mysql_free_result($res);
35  header("Content-type: text/plain");
36  echo implode(', ', $addresses);
37  exit;
38 
39  }
40 }