Пример #1
0
function supporter_array_db($supporter_KEY, $live = NULL)
{
    global $db;
    $sql = "select * from supporter where supporter_KEY = " . $supporter_KEY;
    $S = $db->Execute($sql) or die($db->errorMsg());
    $s = $S->FetchRow();
    if ($live) {
        $sup = new Supporter($s);
        $sup->process_data_augmentation();
        $s = $sup->data;
    }
    #groups
    $sql = 'select * from supporter_groups where supporter_KEY = ' . $supporter_KEY . ' order by Last_Modified desc';
    $G = $db->CacheExecute($sql) or die($db->errorMsg());
    $groups = $G->GetArray();
    foreach ($groups as $key => $i) {
        $sql = 'select groups_KEY, Group_Name, parent_KEY from groups where groups_KEY = ' . $i['groups_KEY'];
        $GD = $db->CacheExecute($sql) or die($db->errorMsg());
        $group_details = $GD->FetchRow();
        $groups[$key]['group'] = $group_details;
    }
    #tags
    $sql = 'select * from tag_data where database_table_KEY=142 and table_key = ' . $supporter_KEY;
    $T = $db->Execute($sql) or die($db->errorMsg());
    $tags = $T->GetArray();
    foreach ($tags as $key => $i) {
        $sql = 'select tag_KEY, prefix, tag, label from tag where tag_KEY = ' . $i['tag_KEY'];
        $TD = $db->Execute($sql) or die($db->errorMsg());
        $tag_details = $TD->FetchRow();
        $tags[$key]['tag'] = $tag_details;
        $tag_name = $tag_details['prefix'] . ':' . $tag_details['tag'];
        $tags[$key]['tag_name'] = $tag_name;
    }
    #actions
    $sql = 'select * from supporter_action where supporter_KEY = ' . $supporter_KEY . ' order by Date_Created desc';
    $A = $db->CacheExecute($sql) or die($db->errorMsg());
    $actions = $A->GetArray();
    foreach ($actions as $key => $i) {
        $sql = 'select action_KEY,Reference_Name from action where action_KEY = ' . $i['action_KEY'] . ' order by Date_Created desc';
        $AD = $db->CacheExecute($sql) or die($db->errorMsg());
        $action_details = $AD->FetchRow();
        $actions[$key]['action'] = $action_details;
    }
    #emails
    $sql = 'select * from email where supporter_KEY = ' . $supporter_KEY . ' order by Time_Sent desc';
    $E = $db->CacheExecute($sql) or die($db->errorMsg());
    $emails = $E->GetArray();
    foreach ($emails as $key => $i) {
        $sql = 'select email_blast_KEY,Subject,Reference_Name,Date_Requested from email_blast where email_blast_KEY = ' . $i['email_blast_KEY'];
        $EB = $db->CacheExecute($sql) or die($db->errorMsg());
        $email_details = $EB->FetchRow();
        $emails[$key]['email'] = $email_details;
    }
    #donations
    $sql = 'select * from donation where supporter_KEY = ' . $supporter_KEY . ' order by Transaction_Date desc';
    $D = $db->CacheExecute($sql) or die($db->errorMsg());
    $donations = $D->GetArray();
    #notes
    $sql = 'select * from contact_history where supporter_KEY = ' . $supporter_KEY . ' and Method = "Note" order by Date_Created desc';
    $N = $db->Execute($sql) or die($db->errorMsg());
    $notes = $N->GetArray();
    #contacts
    $sql = 'select * from contact_history where supporter_KEY = ' . $supporter_KEY . ' and (Method = "Direct Email" or Method ="Phone") order by Date_Created desc';
    $conts = $db->Execute($sql) or die($db->errorMsg());
    $contacts = $conts->GetArray();
    #todos
    $sql = 'select * from contact_history where supporter_KEY = ' . $supporter_KEY . ' and Method = "To Do" order by Date_Created desc';
    $TD = $db->Execute($sql) or die($db->errorMsg());
    $todos = $TD->GetArray();
    #companies
    $sql = 'select * from supporter_company where supporter_KEY = ' . $supporter_KEY;
    $comp = $db->CacheExecute($sql) or die($db->errorMsg());
    $companies = $comp->GetArray();
    #unsub
    $sql = 'select * from unsubscribe where supporter_KEY = ' . $supporter_KEY;
    $unsubs = $db->CacheExecute($sql) or die($db->errorMsg());
    $unsubscribe = $unsubs->GetArray();
    $s['groups'] = $groups;
    $s['tags'] = $tags;
    $s['actions'] = $actions;
    $s['emails'] = $emails;
    $s['donations'] = $donations;
    $s['notes'] = $notes;
    #adds user notes into the notes array, i hope
    if ($s['Notes']) {
        $add_notes[0]['Codes'] = 'Main Note Field';
        $add_notes[0]['Notes'] = $s['Notes'];
        $s['notes'] = array_merge($s['notes'], $add_notes);
    }
    $s['contacts'] = $contacts;
    $s['todos'] = $todos;
    $s['companies'] = $companies;
    $s['unsubscribe'] = $unsubscribe;
    $s = add_computational_data_to_supporter_array($s);
    return $s;
}
Пример #2
0
function search_person($term, $conditons = NULL, $options = NULL)
{
    global $db;
    if ($conditions) {
        foreach ($conditions as $i) {
            $con = ' and  ' . $i;
        }
    }
    if ($options['groups_KEY']) {
        $sql = "SELECT s.supporter_KEY,   Concat(s.First_Name, ' ', s.Last_Name,', ', s.Email) as fullname FROM supporter as s, supporter_groups as g WHERE CONCAT( s.First_Name,  ' ', s.Last_Name, ' ',s.Email, ' ',s.Organization) LIKE  '%" . $term . "%' " . $con . " and s.supporter_KEY = g.supporter_KEY and g.groups_KEY = " . $options['groups_KEY'] . " order by corporate, s.campaign_manager_KEY, Last_Name, First_Name";
    } else {
        $sql = "SELECT *,   Concat(First_Name, ' ', Last_Name,', ', Email) as fullname FROM supporter\n\tWHERE CONCAT( First_Name,  ' ', Last_Name, ' ',Email, ' ',Organization) LIKE  '%" . $term . "%' " . $con . " order by Last_Name, First_Name ";
    }
    $S = $db->Execute($sql) or die($DB->errorMsg());
    $s = $S->GetArray();
    foreach ($s as $supporter) {
        $sup = new Supporter($supporter);
        $sup->process_data_augmentation();
        $out[] = $sup->data;
    }
    return $out;
}