Reach Out|info@aftrr.org
AFTRR AFTRR
  • Home
  • Map Locator
  • About Us
    • About Us
    • Advisory Council
    • Member’s Pledge
    • Become a Member
    • Right to Repair
  • Contact us

Map Locator

Home/Map Locator
, Ethan Burnside * * ,--. * ,--.'| ,----.. ,---,. * ,--,: : | / / \ ,' .' | * ,`--.'`| ' :| : :,---.' | * | : : | |. | ;. /| | .' * : | \ | :. ; /--` : : : * | : ' '; |; | ; : | |-, * ' ' ;. ;| : | | : ;/| * | | | \ |. | '___ | | .' * ' : | ; .'' ; : .'|' : ' * | | '`--' ' | '/ :| | | * ' : | | : / | : \ * ; |.' \ \ .' | | ,' * '---' `---` `----' * * * DESCRIPTION * * This file contains system-wide functions for use * on the cristina.org portals and dTap application. * * FUNCTION LIST * * activate_new_partner($tmp_partnerid) * array_search_ncf($needle, $haystack) * array_stripslashes($value) * base64_url_decode($input) * cache_page($seconds = 10800) * cached_include($key = "welcome", $revision = "") * cf_donation($cfid, $donorid = "", $sessionid = "") * check_do_not_email($address) * chunkFile($path, $table, $id, $delete = false) * clear_lock($key, $user = "", $force = false) * cmp($a, $b) * comment_form($this_key) * content_chunk($depth, $result, $parent_id, $show_desc=true, $list_type="ul", $limit=false) * content_map($parent_id=0, $db="cristina_tmp", $show_desc=true, $list_type="ul", $limit=false, $view_all = false) * count_tag_usage() * create_phpbb3_user($username, $user_email, $user_password, $send_welcome = true, $user_array) * curl_get_file_contents($URL) * diff_days($start_date, $end_date) * display_eligibility($partnerid, $projectid, $display_fixit = true) * display_phone_verification_status($phone_area, $phone_prefix, $phone_suffix, $phone_ext, $scope = "default", $id) * dollarformat($input) * donation_history($partnerid, $sessionid, $donorid, $format = "table_summary", $db = "cristina") * donor_passport_link($donorid = 0, $email = "") * endsWith($haystack, $needle) * embed_images(&$msg_body,$mailer) * error_out($reason = "General Protection Fault

*chuckle*") * feed_category_list() * filter_xss($val) * format_table_name($table, $pluralize = false, $stripunderscores = true, $strtoupper = false, $strtolower = true, $ucwords = true) * gen_random_string($length=5) * get_alerts($scope = "",$partnerid = "",$donorid = "",$userid = "",$alertid = "",$allseen = false) * get_comments($key) * get_donor_array($donorid, $sessionid = "", $use_temp_data = false) * get_generations($table, $showgens = array('1','2','3','4'), $offset = 0, $scope = "dsf", $hidden = 0, $consolidated = true, $return = "display") * get_google_key() * get_link_ref($link_ref) * get_news($id, $dept, $format = "full") * get_partner_array($partnerid, $projectid = "", $locationid = "", $db = "cristina") * get_partner_search_query($preset = '', $status = 'active', $state = '', $date_begin = '', $date_end = '') * getGeo($donorid,$partnerid,$sessionid,$locationid,$database,$table,$update) * getmicrotime() * getNth($n) * getSize($bytes, $id) * is_profile_complete($partnerid, $projectid) * kattare_decode($text, $pass = "Cr1sT1n@") * kattare_encode($text, $pass = "Cr1sT1n@") * list_news($how_many = 5, $section = "all", $format = "list", $category = "", $subcategory = "", $tags = "") * log_this_page($scope = "") * matching_template($donorid, $sessionid, $partnerid) * mime_content_type ($f) * my_get_headers($url) * ncf_ldap_modify($full_name,$info) * ncf_mail($to = "NCF Webmaster ", $from = "NCF Webmaster ", $subject = "Please set a subject...", $body_text = "", $body_html = "", $cc = "", $bcc = "", $priority = "", $attachments = "") * page_is_live($key, $quiet = true) * page_meta($key) * parse_signed_request($signed_request, $secret) * partner_passport_link($partnerid = 0, $email = "") * passport_form($prompt = "Cristina Passport Login") * quoted_printable_encode($string) * rdc_report($partnerid = "") * remove_empty($array) * resize_image($img, $w, $h, $newfilename) * send_diff($differences,$updated_what) * send_file($file_name, $header_message = "") * startsWith($haystack, $needle) * template_cached_include($scope, $templateid, $pageid = "", $no_cache = false) * update_phpbb3_user($user_id, $username, $user_email) * validate_email($email_address) * var_training($post_only_vars,$post_or_get_vars) * */ // As this is one of the first files included we want to make sure // the _SERVER['REMOTE_ADDR'] and _SERVER['HTTPS'] are accurate for all // PHP scripts by detecting if we're behind the haproxy and 'fixing' them... if ($_SERVER['HTTP_X_FORWARDED_FOR']) $_SERVER['REMOTE_ADDR'] = $_SERVER["HTTP_X_FORWARDED_FOR"]; if ($_SERVER['HTTP_X_FORWARDED_PROTO']) $_SERVER['HTTPS'] = "on"; define('DEBUG',false); require_once("mysql_sessions.inc"); if ($_SERVER["HTTP_HOST"] == "proto.cvo.cristina.org" || $_SERVER["HTTP_HOST"] == "proto.cristina.org" || $_SERVER["HTTP_HOST"] == "proto.cristinanetwork.org") { session_register("USE_PROTO_DB"); if ($_GET['USE_PROTO_DB'] != "") { $_SESSION['USE_PROTO_DB'] = $_GET['USE_PROTO_DB']; } $GLOBALS['USE_PROTO_DB'] = $_SESSION['USE_PROTO_DB']; } require_once("db.inc"); require_once("tabs.inc"); if (!function_exists("startsWith")) { function startsWith($haystack, $needle) { // search backwards starting from haystack length characters from the end return $needle === "" || strrpos($haystack, $needle, -strlen($haystack)) !== FALSE; }} if (!function_exists("endsWith")) { function endsWith($haystack, $needle) { // search forward starting from end minus needle length characters return $needle === "" || (($temp = strlen($haystack) - strlen($needle)) >= 0 && strpos($haystack, $needle, $temp) !== FALSE); }} // Get resource scope settings... if (!function_exists("get_scope_settings")) { function get_scope_settings($scopeid) { $scope_result = my_db_query("SELECT * FROM `resource_scopes` WHERE (`id` LIKE '" . mysql_escape_string($scopeid) . "')"); return mysql_fetch_assoc($scope_result); }} // Update the resource tag counts in the resource_tags table... if (!function_exists("update_resource_tags_count")) { function update_resource_tags_count($scopeid, $quiet = false) { $tables = array("resource_article","resource_blog","resource_comment","resource_contact","resource_feedback","resource_file","resource_url","partner_info","resource_organization","resource_video"); $return = "\nWorking on tags with scopeID: {$scopeid}\n"; foreach ($tables as $table) { $tags_result = my_db_query("SELECT `resource_tags_map`.`resource_table`, `resource_tags`.`tag`, `resource_tags`.`id`, COUNT(`resource_tags_map`.`tag_id`) as `tag_total` FROM `{$table}`, `resource_tags_map`, `resource_tags` WHERE (`resource_tags`.`scope` LIKE '" . mysql_escape_string($scopeid) . "') AND (`{$table}`.`status` LIKE 'active' || `status` LIKE 'public') AND (`{$table}`.`id` = `resource_tags_map`.`resource_id`) AND (`resource_tags`.`id` = `resource_tags_map`.`tag_id`) AND (`resource_tags_map`.`resource_table` LIKE '{$table}') GROUP BY `resource_tags_map`.`tag_id` ORDER BY `tag_total` DESC"); if (mysql_numrows($tags_result)) { while ($tags = mysql_fetch_assoc($tags_result)) { $type_ex = explode("_",$tags['resource_table']); if ($type_ex[1] == "info") $type_ex[1] = "partner"; $field_names[$tags['resource_table']] = $type_ex[1] . "_count"; $type_totals[$tags['resource_table']][$tags['tag']] += $tags['tag_total']; $tag_type_totals[$tags['tag']][$table] += $tags['tag_total']; $tag_totals[$tags['tag']] += $tags['tag_total']; $tag_ids[$tags['tag']] = $tags['id']; } } } arsort($tag_totals); $return .= sizeof($tag_totals) . " unique tags found being used...\n"; foreach ($type_totals as $type => $type_array) { arsort($type_totals[$type]); $return .= sizeof($type_array) . " tags assigned to {$type} entries...\n"; } foreach ($tag_type_totals as $tag => $types_array) { unset($article_count,$contact_count,$feedback_count,$file_count,$resource_count,$url_count,$comment_count,$partner_count,$organization_count,$video_count); foreach ($types_array as $table => $count) { $$field_names[$table] = $count; $resource_count += $count; } my_db_query("UPDATE `resource_tags` SET `resource_count` = '{$resource_count}', `article_count` = '{$article_count}', `contact_count` = '{$contact_count}', `feedback_count` = '{$feedback_count}', `file_count` = '{$file_count}', `url_count` = '{$url_count}', `comment_count` = '{$comment_count}', `video_count` = '{$video_count}', `partner_count` = '{$partner_count}' WHERE (`id` = {$tag_ids[$tag]})"); $i++; } $return .= "{$i} database queries performed...\n"; //print_r($tag_totals); //print_r($tag_type_totals); if ($quiet) return $return; else echo $return; }} // Custom report for remote donation channel pledges... if (!function_exists("rdc_report")) { function rdc_report($partnerid = "") { $pledge_result = my_db_query("SELECT * FROM `pledge_notes` WHERE (`note` REGEXP('remote donation channel')) AND (`donorid` NOT LIKE '100') ORDER BY `last_updated` DESC"); if (mysql_numrows($pledge_result)) { $i = 0; while ($note = mysql_fetch_assoc($pledge_result)) { unset($partnerid); $note_parse = explode("partner:",$note['note']); $partnerid = trim(str_replace(".","",$note_parse[1])); if ($partnerid != "100" && $partnerid) { $i++; $orig_partner = get_partner_array($partnerid); $chosen_partners[$partnerid]['name'] = stripslashes($orig_partner['org_name']); $chosen_partners[$partnerid]['count'] += 1; $summary_result = my_db_query("SELECT * FROM `donation_summary` WHERE (`donorid` = '{$note['donorid']}') AND (`sessionid` = '{$note['sessionid']}')"); unset($items); if (mysql_numrows($summary_result)) { while ($item = mysql_fetch_assoc($summary_result)) { $items[$item['table_name']][$item['itemid']] = $item; $match_partnerid = $item['partnerid']; $curr_status = $item['status']; } } if ($curr_status == "matched" || $curr_status == "complete") { if (preg_match("/complete/i",$curr_status)) $color = "green"; else if (preg_match("/matched/i",$curr_status)) $color = "darkolivegreen"; else $color = "inherit"; if ($match_partnerid != $partnerid) { $match_partner = get_partner_array($match_partnerid); $chosen_partners[$partnerid]['summary'] .= "
Donor originally chose " . stripslashes($orig_partner['org_name']) . " but is now {$curr_status} with " . stripslashes($match_partner['org_name']) . ".
\n"; $matched_same_partner++; } else { $match_partner = $orig_partner; $chosen_partners[$partnerid]['summary'] .= "
Donor originally chose " . stripslashes($orig_partner['org_name']) . " and is {$curr_status} with them.
\n"; $matched_diff_partner++; } } else { if (preg_match("/abandon/i",$curr_status)) $color = "red"; else if (preg_match("/reject/i",$curr_status)) $color = "brown"; else if (preg_match("/withdrawn/i",$curr_status)) $color = "saddlebrown"; else $color = "inherit"; $chosen_partners[$partnerid]['summary'] .= "
Donor originally chose " . stripslashes($orig_partner['org_name']) . " but the donation is now {$curr_status}.
\n"; if (($curr_status != "posted") && ($curr_status != "pledged")) { $failed_placements++; } } $chosen_partners[$partnerid]['summary'] .= "
donorID: {$note['donorid']} sessionID: {$note['sessionid']} partnerID: {$partnerid} date: {$note['last_updated']}
\n"; $chosen_partners[$partnerid]['summary'] .= "
"; unset($item_display); foreach ($items as $table_name => $item_array) { foreach ($item_array as $itemid => $item) { if ($item_display) $item_display .= ", "; if ($item['quantity'] > 1) $plural = true; else $plural = false; $item_display .= "{$item['quantity']} " . format_table_name($table_name,$plural); } } $chosen_partners[$partnerid]['summary'] .= "{$item_display}
\n"; } } usort($chosen_partners, "cmp"); foreach ($chosen_partners as $partnerid => $partner) { $partner_breakdown .= "
({$partner['count']})
{$partner['name']}
\n"; $partner_breakdown .= "
{$partner['summary']}
\n"; $total_donations += $partner['count']; } echo "
Total of {$total_donations} donations made to " . sizeof($chosen_partners) . " unique partners:
\n"; echo "
{$partner_breakdown}
\n"; echo "
Matched or Complete with same partner: {$matched_same_partner} (" . number_format($matched_same_partner/$total_donations*100,2) . "%)
\n"; echo "
Matched or Complete with different partner: {$matched_diff_partner} (" . number_format($matched_diff_partner/$total_donations*100,2) . "%)
\n"; echo "
Failed to place equipment with any partner: {$failed_placements} (" . number_format($failed_placements/$total_donations*100,2) . "%)
\n"; } }} // Helper function for usort-ing arrays... if (!function_exists("cmp")) { function cmp($a, $b) { return $b['count'] - $a['count']; }} // Function to activate new partner application... if (!function_exists("activate_new_partner")) { function activate_new_partner($tmp_partnerid) { // Get the partner_info data from cristina_tmp... $partner_tmp_result = my_db_query("SELECT * FROM `partner_info` WHERE (`id` = '" . mysql_escape_string($tmp_partnerid) . "')","cristina_tmp"); if (mysql_numrows($partner_tmp_result)) { $partner_info_tmp = mysql_fetch_assoc($partner_tmp_result); // Make sure this partner doesn't already have an issued partnerID... if (!$partner_info_tmp['issued_partnerid']) { // Insert a new partner_info record in the active db... $partnerid = my_db_query("INSERT INTO `cristina`.`partner_info` (`org_type`, `status`, `member_since`, `priority`, `rating`, `org_name`, `mission`, `training_support`, `staff_full_time`, `staff_part_time`, `staff_voluntary`, `staff_comment`, `501c3_upload`, `501c3_desc`, `501c3_ref`, `aop_upload`, `aop_desc`, `aop_ref`, `refurbisher`, `recycler`) SELECT `org_type`, 'active' as `status`, DATE_FORMAT(NOW(), '%Y%m%d') AS `member_since`, `priority`, `rating`, `org_name`, `mission`, `training_support`, `staff_full_time`, `staff_part_time`, `staff_voluntary`, `staff_comment`, `501c3_upload`, `501c3_desc`, `501c3_ref`, `aop_upload`, `aop_desc`, `aop_ref`, `refurbisher`, `recycler` FROM `cristina_tmp`.`partner_info` WHERE (`partner_info`.`id` = '" . mysql_escape_string($tmp_partnerid) . "')"); // Fix the 501c3 upload reference... if ($partner_info_tmp['501c3_upload']) { $upload_result = my_db_query("SELECT * FROM `501c3_uploads` WHERE (`id` = '" . mysql_escape_string($partner_info_tmp['501c3_upload']) . "')"); if (mysql_numrows($upload_result)) { $upload = mysql_fetch_assoc($upload_result); // Update the partner_info record so it points to the proper uploaded file information... my_db_query("UPDATE `partner_info` SET `501c3_upload` = '" . mysql_escape_string($upload['filename']) . "', `501c3_desc` = '" . mysql_escape_string($upload['file_info']) . "', `501c3_ref` = '" . mysql_escape_string($upload['id']) . "' WHERE (`id` = '{$partnerid}')"); // Update the upload entry to have the proper permanent partnerid... my_db_query("UPDATE `501c3_uploads` SET `partnerid` = '" . mysql_escape_string($partnerid) . "' WHERE (`id` = {$upload['id']})"); } } // Insert a new partner_project record in the active db... if ($partnerid) { $projectid = my_db_query("INSERT INTO `cristina`.`partner_project` (`project_status`, `priority`, `project_date`, `partner_id`, `project_name`, `project_location`,`project_abstract`, `needs_statement`, `project_objectives`, `target_pop`, `expected_outcomes`, `technical_support`, `hardware_used`, `software_used`, `project_scope`, `total_sites`, `pickup_range`, `have_pickup`, `donation_size`, `storage_capacity`, `repair_capability`, `repair_annually`, `repair_distribution`, `install_tech_support`, `install_os`, `install_apps`, `templateid`, `overall_theme`, `needs_templateid`, `custom_logo`, `custom_terms`, `custom_subscription`, `logo_position`, `field_color`, `accept_terms`, `show_loc`, `provide_directions`, `receive_updates`, `set_options`) SELECT `project_status`, `priority`, `project_date`, '{$partnerid}' AS `partner_id`, `project_name`, `project_location`, `project_abstract`,`needs_statement`, `project_objectives`, `target_pop`, `expected_outcomes`, `technical_support`, `hardware_used`, `software_used`, `project_scope`, `total_sites`, `pickup_range`, `have_pickup`, `donation_size`, `storage_capacity`, `repair_capability`, `repair_annually`, `repair_distribution`, `install_tech_support`, `install_os`, `install_apps`, `templateid`, `overall_theme`, `needs_templateid`, `custom_logo`, `custom_terms`, `custom_subscription`, `logo_position`, `field_color`, `accept_terms`, `show_loc`, `provide_directions`, `receive_updates`, `set_options` FROM `cristina_tmp`.`partner_project` WHERE (`partner_project`.`partner_id` = '" . mysql_escape_string($tmp_partnerid) . "')"); if (!$projectid) $error_msgs .= "No partner_project entry made... let Brian know you got this error!\n"; } // Insert contacts... my_db_query("INSERT INTO `cristina`.`partner_contacts` (`contact_type`, `partnerid`, `name`, `title`, `phone_area`, `phone_prefix`, `phone_suffix`, `phone_ext`, `fax_area`, `fax_prefix`, `fax_suffix`, `email`, `address_line1`, `address_line2`, `city`, `state`, `zip`, `country`, `staff_notes`) SELECT `contact_type`, '{$partnerid}' AS `partnerid`, `name`, `title`, `phone_area`, `phone_prefix`, `phone_suffix`, `phone_ext`, `fax_area`, `fax_prefix`, `fax_suffix`, `email`, `address_line1`, `address_line2`, `city`, `state`, `zip`, `country`, `staff_notes` FROM `cristina_tmp`.`partner_contacts` WHERE (`partner_contacts`.`partnerid` = '" . mysql_escape_string($tmp_partnerid) . "')"); // Insert locations... my_db_query("INSERT INTO `cristina`.`partner_locations` (`status`, `locator`, `verified_phoneid`, `location_type`, `partnerid`, `projectid`, `location_name`, `address1`, `address2`, `city`, `state`, `region`, `country`, `zip`, `phone_area`, `phone_prefix`, `phone_suffix`, `phone_ext`, `fax_area`, `fax_prefix`, `fax_suffix`, `email`, `url`, `lat`, `lon`, `set_manually`, `refurbisher`, `recycler`) SELECT `status`, `locator`, `verified_phoneid`, `location_type`, '{$partnerid}' AS `partnerid`, '{$projectid}' AS `projectid`, 'Main Location' AS `location_name`, `address1`, `address2`, `city`, `state`, `region`, `country`, `zip`, `phone_area`, `phone_prefix`, `phone_suffix`, `phone_ext`, `fax_area`, `fax_prefix`, `fax_suffix`, `email`, `url`, `lat`, `lon`, `set_manually`, '{$partner_info_temp['refurbisher']}', '{$partner_info_temp['recycler']}' FROM `cristina_tmp`.`partner_locations` WHERE (`partner_locations`.`partnerid` = '" . mysql_escape_string($tmp_partnerid) . "')"); // Link locations... $locations_result = my_db_query("SELECT `id` FROM `partner_locations` WHERE (`partnerid` = '{$partnerid}')"); if (mysql_numrows($locations_result)) { while ($location = mysql_fetch_assoc($locations_result)) { $linkid = my_db_query("INSERT INTO `partner_locations_link` (`partnerid`, `projectid`, `locationid`) VALUES ('{$partnerid}', '0', '{$location['id']}')"); // Attempt to get lat/lon coords for this location... getGeo("",$partnerid,"",$location['id'],"cristina","partner_locations",true); } } else { $error_msgs .= "No partner locations found!\n"; } // Get placement contactid... $placement_result = my_db_query("SELECT `placement_contact` FROM `partner_project` WHERE (`partner_id` = '" . mysql_escape_string($tmp_partnerid) . "')", "cristina_tmp"); // Create placement contact passport entry... if (mysql_numrows($placement_result)) { $contactid = mysql_result($placement_result,0,"placement_contact"); if ($contactid) { $contact_result = my_db_query("SELECT * FROM `partner_contacts` WHERE (`id` = '{$contactid}')", "cristina_tmp"); if (mysql_numrows($contact_result)) { $placement = mysql_fetch_assoc($contact_result); if ($placement['name'] && $placement['title'] && $placement['email']) { $new_info = get_partner_array($partnerid); $new_passport_array['user_type'] = 0; $new_passport_array['group_id'] = 71; $new_passport_array['user_occ'] = $placement['title']; if (strlen($new_info['url']) > 5) { if (preg_match('|^https*://|', $new_info['url']) === 0) $new_info['url'] = 'http://' . $new_info['url']; $new_passport_array['user_website'] = $new_info['url']; } $new_passport_array['user_from'] = $new_info['city'] . ", " . $new_info['state'] . " (partnerID: {$partnerid})"; // Finally, pass contact information to phpbb3 creation function... //$oldb = $db; //unset($db, $GLOBALS['db']); //echo "create_phpbb3_user({$placement['name']}, {$placement['email']}, {$partnerid}, \"0\", {$new_passport_array});\n"; //print_r($new_passport_array); //$phpbb_user_id = create_phpbb3_user($placement['name'], $placement['email'], $partnerid, "0", $new_passport_array); //$db = $oldb; } else { $error_msgs .= "Name, title and email not entered properly for placement contact. No Cristina Passport created!\n"; } } } else { $error_msgs .= "Placement contactID not specified. No Cristina Passport created!\n"; } } else { $error_msgs .= "Partner Project db entry not found... let Brian know you saw this!\n"; } // Enter placement contact entry... if ($phpbb_user_id && $projectid && $new_info['main_locationid']) { $contact_result = my_db_query("SELECT * FROM `partner_contacts` WHERE (`partnerid` = '{$partnerid}') AND (`name` LIKE '" . mysql_escape_string($placement['name']) . "') AND (`title` LIKE '" . mysql_escape_string($placement['title']) . "') AND (`email` LIKE '" . mysql_escape_string($placement['email']) . "')"); if (mysql_numrows($contact_result)) { $pcontactid = mysql_result($contact_result,0,"id"); my_db_query("INSERT INTO `placement_contacts` (`partnerid`, `projectid`, `locationid`, `contactid`, `phpbb_user`) VALUES('{$partnerid}', '{$projectid}', '{$new_info['main_locationid']}', '{$pcontactid}', '{$phpbb_user_id}')"); } else { $error_msgs .= "Placement contact not entered, no partner_contacts entry found matching name, title and email!\n"; } } else { $error_msgs .= "Placement contact not entered, missing phpbb_user_id ({$phpbb_user_id}), projectid ({$projectid}) or locationid ({$new_info['main_locationid']})\n"; } // Update the status of the tmp record to accepted... $today = date("YmdHis"); my_db_query("UPDATE `partner_info` SET `status` = 'accepted', `issued_partnerid` = '{$partnerid}', `last_updated` = '{$today}' WHERE (`id` = '{$tmp_partnerid}')", "cristina_tmp"); // Insert last_updated entry to mark activation... my_db_query("INSERT INTO `cristina`.`last_updated` (`partnerid`, `updated_what`, `updated_when_bak`, `updated_when`, `updated_by`) VALUES ('{$partnerid}', 'new_partner_activation', '" . date("Ymd") . "', NOW( ) , 'brian')"); } else { $error_msgs .= "Already issued partnerID ({$partner_info_tmp['issued_partnerid']})\n"; } } else { $error_msgs .= "Error! No such partner record found ({$tmp_partnerid})\n"; } return array("issued_partnerid" => $partnerid, "error_msgs" => $error_msgs, "phpbb_user_id" => $phpbb_user_id); }} // Function to decode the Facebook signed_request post... if (!function_exists("parse_signed_request")) { function parse_signed_request($signed_request, $secret) { list($encoded_sig, $payload) = explode('.', $signed_request, 2); // decode the data $sig = base64_url_decode($encoded_sig); $data = json_decode(base64_url_decode($payload), true); if (strtoupper($data['algorithm']) !== 'HMAC-SHA256') { error_log('Unknown algorithm. Expected HMAC-SHA256'); return null; } // check sig $expected_sig = hash_hmac('sha256', $payload, $secret, $raw = true); if ($sig !== $expected_sig) { error_log('Bad Signed JSON signature!'); return null; } return $data; }} // Helper function for Facebook signed_request parsing... if (!function_exists("base64_url_decode")) { function base64_url_decode($input) { return base64_decode(strtr($input, '-_', '+/')); }} if (!function_exists('remove_empty')) { function remove_empty($array) { foreach ($array as $key => $value) { if ($value) { $returnarray['$key'] = $value; } } return $returnarray; }} if (!function_exists('send_diff')) { function send_diff($differences,$updated_what) { global $user; $partner = get_partner_array($GLOBALS['partnerid'],$GLOBALS['projectid']); require_once ("Text/Diff.php"); require_once ("Text/Diff/Renderer/inline.php"); $renderer = new Text_Diff_Renderer_inline(); if (is_array($differences) && sizeof($differences) > 0) { $body_html = "{$partner['org_name']} changed the following information on their Cristina Network Profile:

\n"; $body_html .= "

\n"; $body_html .= " \n"; $body_html .= " \n"; $body_html .= " \n"; $body_html .= " \n"; $body_html .= " \n"; $body_text = "{$partner['org_name']} changed the following information on their Cristina Network Profile:\n\n"; $send_report = 0; foreach ($differences as $key => $value) { if ($rowcolor == "#F2F2F2") { $rowcolor = "#FFFFFF"; } else { $rowcolor = "#F2F2F2"; } if ($value['report'] == "true") { $send_report = 1; } if ($value['show_diff'] == "true") { $diff = new Text_Diff(explode("\n",$value['old_value']), explode("\n",$value['new_value'])); $diff_output = $renderer->render($diff); $new_value_html = str_replace("\n","
\n",$diff_output); } else { $new_value_html = str_replace("\n","
\n",$value['new_value']); } $old_value_html = str_replace("\n","
\n",$value['old_value']); $body_html .= " \n"; $body_html .= " \n"; $body_html .= " \n"; $body_html .= " \n"; $body_html .= " \n"; $body_text .= "FIELD: {$key}\nOLD VALUE: {$value['old_value']}\nNEW VALUE: {$value['new_value']}\n\n"; // Update the last_updated table... $now = date("F j, Y, g:i a"); if ($update_what && !$update) { $update = $update_what; } my_db_query("INSERT INTO last_updated (db, partnerid, updated_who, updated_what, updated_detail, old_value, new_value, updated_when, updated_by, date) values ('partner', '{$GLOBALS['partnerid']}', '{$GLOBALS['partnerid']}', '" . mysql_escape_string($updated_what) . "', '{$key}', '" . mysql_escape_string($value['old_value']) . "', '" . mysql_escape_string($value['new_value']) . "', NOW(), '{$user->data['user_id']}', " . time() . ")"); } $body_html .= "
FIELDOLD VALUENEW VALUE
{$key}{$old_value_html}{$new_value_html}

\n"; $body_html .= "Changes were made by {$user->data['username']} on " . date("F j, Y, g:i a") . "

\n"; $body_text .= "Changes were made by {$user->data['username']} on " . date("F j, Y, g:i a") . "\n\n"; // Wrap html text with proper html/css... $body_html = "\n\n\n\n\n" . $body_html . "\n\n"; // Who to send to... $to = "partner_updates@cristina.org"; $to_name = "NCF Staff"; // Send the email report... if ($send_report) { ncf_mail($to = "{$to_name} <{$to}>", $from = "NCF Webmaster ", $subject = "Partner Record Updated ({$GLOBALS['partnerid']})...", $body_text, $body_html, $cc = "", $bcc = "", $priority = "", $attachments = ""); } } }} if (!function_exists('sentence_case')) { function sentence_case($string) { $string_array = explode("\n",$string); foreach ($string_array as $string) { $sentences = preg_split('/([.?!]+)/', $string, -1, PREG_SPLIT_NO_EMPTY|PREG_SPLIT_DELIM_CAPTURE); $new_string = ''; foreach ($sentences as $key => $sentence) { $new_string .= ($key & 1) == 0? ucfirst(strtolower(trim($sentence))) : $sentence.' '; } $return .= $new_string . "\n"; } return trim($return); }} if (!function_exists('display_eligibility')) { function display_eligibility($partnerid, $projectid, $display_fixit = true) { global $userdata; // Get eligibility array return... $eligible = isEligible($partnerid,$projectid,"cgpn"); //$output .= "

" . print_r($eligible,true) . "
\n"; // $conditions['has_passing_location'] = true; // Check to make sure the partner has active status... $status_result = my_db_query("SELECT `id` FROM `partner_info` WHERE (`status` like 'active%') AND (`id` = {$partnerid})"); // Check to make sure the project has proper status... $project_status_result = my_db_query("SELECT `id` FROM `partner_project` WHERE (`project_status` like 'active' or `project_status` like 'current')"); // Assign condition fixit buttons... $fixit = array("has_mission_statement" => '
', "aop_terms_conditions" => '
', "has_needs" => '
', "placement_contact_specified" => '
', "has_geo-located_address" => '
', "has_verified_phone" => '
', "set_publishing_options" => '
'); // Override aop_terms fixit button with update button where applicable... if ($eligible[$projectid]['aop_terms_conditions']) { $aop_terms_result = my_db_query("SELECT * FROM `aop_terms` WHERE (`partnerid` = '" . mysql_escape_string($partnerid) . "') ORDER BY `id` DESC LIMIT 1"); if (mysql_numrows($aop_terms_result)) { $aop_existing = mysql_fetch_assoc($aop_terms_result); // Reasons to display update button include: // 1) The terms in storage is a file upload // 2) The terms in storage was signed by a different user // 3) The terms in storage was signed before the timestamp of the agreement file if ($aop_existing['uploadid'] || ($aop_existing['phpbb_user_id'] != $userdata['user_id']) || (strtotime($aop_existing['date_signed']) < filemtime("includes/aop_terms.inc"))) { $fixit['aop_terms_conditions'] = '
'; $update_aop = true; //$output .= "\n"; } } } //$output .= "(Click for more help...)
]\" style=\"cursor: pointer;float:right;\" src=\"images/help_icon.png\">\n"; //$output .= "
In order for this project to be listed publicly and begin receiving donations, each of the following conditions must be met...
\n"; $output .= "\n"; $output_email .= "
\n"; $num_passed = 0; $num_failed = 0; foreach ($eligible[$projectid] as $condition => $value) { if ($condition && is_int($condition)) { // must be a locationid... } elseif ($condition && ($condition != "overall_eligibility")) { $output .= " \n"; //$output .= "
" . str_replace("And","and",ucwords(str_replace("_"," ",$condition))) . "
"; $output .= " \n"; $output_email .= " \n"; $output_email_text .= str_replace("And","and",str_replace("Aop","Award of Property",ucwords(str_replace("terms conditions","Agreement",str_replace("_"," ",$condition))))) . ": "; if (!$value) { $display_value = "Fail"; $style_color = "color:red"; $overall_color = "color:red"; $fixit_button = $fixit[$condition]; } else { $display_value = "Pass"; $style_color = ""; if (($condition == "aop_terms_conditions") && $update_aop) $fixit_button = $fixit[$condition]; else unset($fixit_button); } if ($display_fixit) { //$output .= "
{$fixit_button}{$display_value}

\n"; $location_result = my_db_query("SELECT partner_locations.* FROM partner_locations_link LEFT JOIN partner_locations ON partner_locations.id = partner_locations_link.locationid WHERE (partner_locations_link.partnerid = {$partnerid}) AND (partner_locations_link.projectid = '')"); if (mysql_numrows($location_result)) { $location = mysql_fetch_assoc($location_result); $locationid = $location['id']; } $fixit_button = str_ireplace("[locationid]", $locationid, $fixit_button); if ($location['lat'] && $location['lon'] && ($display_value == "Pass") && ($condition == "has_geo-located_address")) { //$preview_button = "
"; $latlon = $location['lat'] . "," . $location['lon']; } else { unset($preview_button); } $output .= " \n"; } else { //$output .= "
{$display_value}

\n"; $output .= " \n"; $output_email .= " \n"; $output_email_text .= " {$display_value}\n"; } $output .= " \n"; $output_email .= " \n"; if ($condition == "has_verified_location") { foreach ($eligible[$projectid] as $locationid => $location_values) { // $output .= "id $locationid ... "; if ($locationid && is_int($locationid)) { foreach ($location_values as $name => $somevalue) { if ($name == "location_overall") { // skip... } elseif ($name == "name") { $output .= " \n"; $output_email .= " \n"; /* $output .= "
\n"; $output .= "
\n"; $output .= "
" . str_replace("And","and",ucwords(str_replace("_"," ",stripslashes($somevalue)))) . "
"; */ $output .= "
\n"; $output_email .= " \n"; $output_email_text .= str_replace("And","and",ucwords(str_replace("_"," ",stripslashes($somevalue)))) . ": "; if (!$location_values['location_overall']) { $display_value = "Fail"; $overall_color = "color:red"; $style_color = "color:red"; $num_failed++; } else { $display_value = "Pass"; $style_color = ""; $num_passed++; } $display_size = "100%"; unset($fixit_button); // Get location's lat/lon... $location_result = my_db_query("SELECT * FROM `partner_locations` WHERE (`id` = {$locationid})"); if (mysql_numrows($location_result)) { $loc = mysql_fetch_assoc($location_result); if ($loc['lat'] && $loc['lon']) { // Check to make sure the partner/project has active status... if (mysql_numrows($status_result) && mysql_numrows($project_status_result) && ($display_value != "Fail")) { $preview_button = "
"; } } } /* $output .= "
{$display_value}

\n"; $output .= "\n"; $output .= "
\n"; */ $output .= "
\n"; $output_email .= " \n"; $output_email_text .= " {$display_value}\n"; $output .= " \n"; $output_email .= " \n"; unset($preview_button); } else { $output .= " \n"; $output_email .= " \n"; if (!$somevalue) { $display_value = "Fail"; $display_size = "100%"; $style_color = "color:red"; $overall_color = "color:red"; $fixit_button = $fixit[$name]; } else { $display_value = "Pass"; $display_size = "100%"; $style_color = ""; unset($fixit_button); } //$output .= "
" . str_replace("And","and",ucwords(str_replace("_"," ",$name))) . "
"; $output .= " \n"; $output_email .= " \n"; $output_email_text .= " - " . str_replace("And","and",ucwords(str_replace("_"," ",$name))) . ": "; if ($display_fixit) { //$output .= "
{$fixit_button}{$display_value}

\n"; $fixit_button = str_ireplace("[locationid]", $locationid, $fixit_button); $output .= " \n"; } else { //$output .= "
{$display_value}

\n"; $output .= " \n"; $output_email .= " \n"; $output_email_text .= " {$display_value}\n"; } $output .= " \n"; $output_email .= " \n"; } } //$output .= "\n"; // end hidden div } } } } } $output .= "
" . str_replace("And","and",str_replace("Aop","Award of Property",str_replace("Terms Conditions","Agreement",ucwords(str_replace("_"," ",$condition))))) . "" . str_replace("And","and",str_replace("Aop","Award of Property",ucwords(str_replace("terms conditions","Agreement",str_replace("_"," ",$condition))))) . "{$fixit_button}{$preview_button}{$display_value}{$display_value}{$display_value}
"; $output .= "
 
"; $output .= str_replace("And","and",ucwords(str_replace("_"," ",stripslashes($somevalue)))) . "
" . str_replace("And","and",ucwords(str_replace("_"," ",stripslashes($somevalue)))) . "
{$preview_button}{$display_value}{$display_value}
" . str_replace("And","and",ucwords(str_replace("_"," ",$name))) . "" . str_replace("And","and",ucwords(str_replace("_"," ",$name))) . "{$fixit_button}{$display_value}{$display_value}{$display_value}
\n"; $output_email .= "\n"; $output_email_text .= "\n"; //if (($eligible[$projectid]['overall_eligibility'] != "PASS") && $display_fixit) { if ($display_fixit && $num_failed) { $output .= "
Update All Settings
\n"; } else if ($display_fixit) { $output .= "
\n"; $output .= "
Update All Settings
\n"; $output .= "
Donor Form Settings
\n"; $output .= "
Verify Phone Number
\n"; $output .= "
\n"; } if (!$eligible[$projectid]['has_verified_location'] && ($eligible[$projectid]['overall_eligibility'] == "PASS")) { $num_passed++; } // Mark overall eligibility to FAIL when partner/project status not active... if (!mysql_numrows($status_result) || !mysql_numrows($project_status_result)) { $eligible[$projectid]['overall_eligibility'] = "FAIL"; $overall_color = "color:red"; } $output .= "
Overall Eligibility:
"; $output .= "
{$eligible[$projectid]['overall_eligibility']}


\n"; //$output .= "Want to see how your donors are going to find you?
\n"; $output_email .= "
Overall Eligibility:
"; $output_email .= "
{$eligible[$projectid]['overall_eligibility']}


\n"; $output_email_text .= "Overall Eligibility: {$eligible[$projectid]['overall_eligibility']}\n\n"; if ($latlon) { $locator_link = ""; $locator_endlink = ""; } if (mysql_numrows($status_result) && mysql_numrows($project_status_result)) { if ($num_passed && $num_failed && ($eligible[$projectid]['overall_eligibility'] == "PASS")) { $analysis .= "Congratulations, at least one of your project locations is currently listed in the Non-Profit Locator! At this time, "; if ($num_failed > 1) { $analysis .= "{$num_failed} locations are"; } else { $analysis .= "{$num_failed} location is"; } $analysis .= " not eligible due to problems outlined below.\n"; } else if ($num_passed && !$num_failed && ($eligible[$projectid]['overall_eligibility'] == "PASS")) { $analysis .= "Congratulations, all project locations are currently listed in the {$locator_link}Non-Profit Locator!{$locator_endlink}\n"; if ($num_passed > 1) { $analysis .= " Click the buttons next to each of your locations below to see your project as donors will see it."; } } else if ((!$num_passed && $num_failed) || ($eligible[$projectid]['overall_eligibility'] != "PASS")) { $analysis .= "There are items below that must be corrected before your project can be published in the Non-Profit locator.\n"; } else { $analysis .= "Fail: {$num_failed}, Pass: {$num_passed}"; } } else { if (!mysql_numrows($status_result)) { $analysis .= "Your organization's Cristina Network account is not currently active and so cannot appear in the Non-Profit Locator. If you feel this is in error, please contact webmaster@cristina.org."; } else { $analysis .= "Your project is not currently active and so cannot appear in the Non-Profit Locator. To change this, adjust the Operational Status option in the Project Details section."; } } /* if ($eligible[$projectid]['overall_eligibility'] == "PASS") { if ($num_passed) { $output .= "
Congratulations, at least one of your project locations is currently listed in the Non-Profit Locator!
\n"; } } else { if ($display_fixit) { $output .= "
There are items above that must be corrected before your project can be published in the Non-Profit locator. Click the button marked "FIX IT" to correct each issue.
\n"; } else { $output .= "
There are items above that must be corrected before your project can be published in the Non-Profit locator.
\n"; } } */ $return['conditions'] = $eligible[$projectid]; $return['num_passed'] = $num_passed; $return['num_failed'] = $num_failed; $return['table'] = $output; $return['table_email'] = $output_email; $return['table_email_text'] = $output_email_text; $return['summary'] = $analysis; $return['summary_above'] = str_replace("below","above",$analysis); $return['summary_below'] = str_replace("above","below",$analysis); //echo "{$analysis}{$output}"; return $return; }} // Image resize that maintains transparency... if (!function_exists('resize_image')) { function resize_image($img, $w, $h, $newfilename) { //Check if GD extension is loaded if (!extension_loaded('gd') && !extension_loaded('gd2')) { trigger_error("GD is not loaded", E_USER_WARNING); return false; } //Get Image size info $imgInfo = getimagesize($img); switch ($imgInfo[2]) { case 1: $im = imagecreatefromgif($img); break; case 2: $im = imagecreatefromjpeg($img); break; case 3: $im = imagecreatefrompng($img); break; default: trigger_error('Unsupported filetype!', E_USER_WARNING); break; } //If image dimension is smaller, do not resize if ($imgInfo[0] <= $w && $imgInfo[1] <= $h) { $nHeight = $imgInfo[1]; $nWidth = $imgInfo[0]; } else { //yeah, resize it, but keep it proportional if ($w/$imgInfo[0] > $h/$imgInfo[1]) { $nWidth = $w; $nHeight = $imgInfo[1]*($w/$imgInfo[0]); } else { $nWidth = $imgInfo[0]*($h/$imgInfo[1]); $nHeight = $h; } } $nWidth = round($nWidth); $nHeight = round($nHeight); $newImg = imagecreatetruecolor($nWidth, $nHeight); // Check if this image is PNG or GIF, then set if Transparent if(($imgInfo[2] == 1) OR ($imgInfo[2] == 3)){ imagealphablending($newImg, false); imagesavealpha($newImg,true); $transparent = imagecolorallocatealpha($newImg, 255, 255, 255, 127); imagefilledrectangle($newImg, 0, 0, $nWidth, $nHeight, $transparent); } imagecopyresampled($newImg, $im, 0, 0, 0, 0, $nWidth, $nHeight, $imgInfo[0], $imgInfo[1]); //Generate the file, and rename it to $newfilename switch ($imgInfo[2]) { case 1: imagegif($newImg,$newfilename); break; case 2: imagejpeg($newImg,$newfilename); break; case 3: imagepng($newImg,$newfilename); break; default: trigger_error('Failed to resize image!', E_USER_WARNING); break; } return $newfilename; }} // Enter Craters & Freighters donation or record hit... if (!function_exists('cf_donation')) { function cf_donation($cfid, $donorid = "", $sessionid = "") { if (!$donorid && !$sessionid) { // Track hit... my_db_query("update `cf_franchises` set `hits` = `hits` + 1 where (`id` = " . mysql_escape_string($cfid) . ")"); } else { // Check to see if it already exists... $cf_result = my_db_query("select * from `cf_donations` where (`sessionid` like '" . mysql_escape_string($sessionid) . "') and (`donorid_tmp` = " . mysql_escape_string($donorid) . ")"); if (!mysql_numrows($cf_result)) { // Track (insert) donation... $insertid = my_db_query("insert into `cf_donations` (`cfid`,`donorid_tmp`,`sessionid`) values ('" . mysql_escape_string($cfid) . "','" . mysql_escape_string($donorid) . "','" . mysql_escape_string($sessionid) . "')"); } } }} // Check to see if a partner's profile is complete... if (!function_exists('is_profile_complete')) { function is_profile_complete($partnerid, $projectid) { //$field_array = array("org_name" => "partner_info", }} // LDAP function to modify a contact... if (!function_exists('ncf_ldap_modify')) { function ncf_ldap_modify($full_name,$info) { $lc = ldap_connect("ldap://mail.cristina.org") or die("Could not connect to ldap"); ldap_set_option($lc, LDAP_OPT_PROTOCOL_VERSION,3); if ($lc) { $ldapbind = ldap_bind($lc, "cn=Ethan Burnside,dc=cristina,dc=org", "redbear"); // verify binding if ($ldapbind) { echo "LDAP bind successful...\n"; } else { echo "LDAP bind failed...\n"; ldap_close($lc); exit; } } if (ldap_modify($lc, "cn={$full_name},ou=contacts,dc=cristina,dc=org", $info)) { echo "Entry {$full_name} updated!\n"; } else { if (ldap_add($lc, "cn={$full_name},ou=contacts,dc=cristina,dc=org", $info)) { echo "Entry {$full_name} added!\n"; } else { echo "Entry {$full_name} FAILED!\n"; echo ldap_error($lc) . "\n"; print_r($info); echo "\n"; } } }} // // our own little array search function // if (!function_exists('array_search_ncf')) { function array_search_ncf($needle, $haystack) { $match = false; foreach ($haystack as $key => $value) { if ($value == $needle) { $match = $key; } } return $match; }} // // function to change a passport username or email // if (!function_exists('update_phpbb3_user')) { function update_phpbb3_user($user_id, $username, $user_email) { // // some of the phpbb3 stuff requires globals $phpbb_root_path, $phpEx // $GLOBAL['phpbb_root_path'] = "/www/proto/phpbb3/"; $GLOBAL['phpEx'] = "php"; // // these are built into php // $user_email_hash = (crc32(strtolower($user_email)) . strlen($user_email)); // // this one is from phpbb3/includes/utf/utf_tools.php // require_once($GLOBAL['phpbb_root_path'] . "includes/utf/utf_tools." . $GLOBAL['phpEx']); $username_clean = utf8_clean_string($username); // // the actual update query // if ($user_email) { my_db_query("UPDATE users SET username='" . mysql_escape_string($username) . "', username_clean='" . mysql_escape_string($username_clean) . "', user_email='" . stripslashes(mysql_escape_string($user_email)) . "', user_email_hash='" . mysql_escape_string($user_email_hash) . "' WHERE user_id = $user_id", "phpbb3"); } else { my_db_query("UPDATE users SET username='" . mysql_escape_string($username) . "', username_clean='" . mysql_escape_string($username_clean) . "' WHERE user_id = $user_id", "phpbb3"); } // // update the username throughout the discussions section... // // this one is from phpbb3/includes/functions_user_ncf.php // // // we need to know the old username // $result = my_db_query("SELECT username FROM users WHERE user_id = $user_id", "phpbb3"); $result_array = mysql_fetch_assoc($result); $old_username = $result_array['username']; require_once($GLOBAL['phpbb_root_path'] . "includes/functions_user_ncf." . $GLOBAL['phpEx']); user_update_name($old_username, $username); } } // // function to create a passport (phpbb3 user) // if (!function_exists('create_phpbb3_user')) { function create_phpbb3_user($username, $user_email, $user_password, $send_welcome = true, $user_array) { global $db, $auth, $userdata, $user, $welcome_message, $update_text, $phpEx, $phpbb_root_path, $config, $partnerid; //echo "
\ncreate_phpbb3_user() called with the following params:\n{$username}, {$user_email}, {$user_password}, {$send_welcome}, " . print_r($user_array, true) . "
\n"; // // some of the phpbb3 stuff requires globals $phpbb_root_path, $phpEx // $GLOBAL['phpbb_root_path'] = "/www/proto/phpbb3/"; $GLOBAL['phpEx'] = "php"; //echo "
\nTrying to include utf_tools.php and functions_user_ncf.php
\n"; //require_once($GLOBAL['phpbb_root_path'] . 'common.php'); //require_once($GLOBAL['phpbb_root_path'] . 'includes/ucp/ucp_register.php'); //require_once($GLOBAL['phpbb_root_path'] . "includes/db/dbal." . $GLOBAL['phpEx']); require_once($GLOBAL['phpbb_root_path'] . "includes/utf/utf_tools." . $GLOBAL['phpEx']); require_once($GLOBAL['phpbb_root_path'] . "includes/functions_user_ncf." . $GLOBAL['phpEx']); //echo "
\nincludes called...
\n"; $user_array['username'] = $username; $user_array['user_email'] = $user_email; if ($user_array['user_type'] == "") $user_array['user_type'] = 0; if ($user_array['group_id'] == "") $user_array['group_id'] = 71; $user_array['user_password'] = phpbb_hash($user_password); // // these can be passed in via the array arg... // // $user_array['user_occ'] = $user_occ; // $user_array['user_website'] = $user_website; // $user_array['user_from'] = $user_from; // // little trick to get the db pointer flipped over to the phpbb3 database // so that we can use the phpbb_hash and user_add functions. // my_db_query("use phpbb3", "phpbb3"); // // phpbb3 function to add a user... // //echo "calling user_add() with array:\n" . print_r($user_array,true); $phpbb_user_id = user_add($user_array); group_user_add(9, array($phpbb_user_id)); // Set the aes_password in the ncf_fields table... if ($user_password != "") { include_once('Crypt/AES.php'); $aes = new Crypt_AES(); $aes->setKey('NCF AES Password Key'); $aes_password = base64_encode($aes->encrypt($user_password)); $sql = "INSERT INTO ncf_fields (user_id, aes_password) VALUES ($phpbb_user_id, '$aes_password') ON DUPLICATE KEY UPDATE aes_password = '$aes_password'"; $db->sql_query($sql); } $update_text = "ACCOUNT CREATED"; if ($send_welcome) { if ($welcome_message == "") { $welcome_message = "Greetings, Please click the link below to gain access to the Cristina Network website. Be sure to use the following details when entering your Cristina Passport or you will not be able to access the website and collaborate with your colleagues. [PASSPORT_DETAILS] We look forward to seeing you online!"; } $cc = "brian@cristina.org"; if ($username && $user_email) { $to = "{$username} <{$user_email}>"; } else { $to = $user_email; } $from = "{$user->data['username']} <{$user->data['user_email']}>"; $passport_details = "Cristina Network URL: https://www.cristinanetwork.org/\n"; $passport_details .= " Email: " . $user_email . "\n"; //$passport_details .= "Username: " . $username . "\n"; $passport_details .= "Password: " . $user_password . "\n"; $body_text = preg_replace("/\[PASSPORT_DETAILS\]/i", $passport_details, $welcome_message); ncf_mail($to, $from, 'Your NEW Cristina Network Account...', $body_text, '', $cc, $bcc, $priority, ''); $update_text .= " - EMAIL SENT"; } my_db_query("use cristina", "cristina"); // Link this passport to this partnerid... if ($partnerid) { my_db_query("INSERT INTO `partner_passport_link` (`phpbb_user_id`,`partnerid`) VALUES ('{$phpbb_user_id}','{$partnerid}')"); } return $phpbb_user_id; } } // Slightly more refined microtime method... if (!function_exists('getmicrotime')) { function getmicrotime() { $mtime = microtime(); $mtime = explode(" ",$mtime); $mtime = $mtime[1] + $mtime[0]; return ($mtime); } } // Returns a properly formatted table name (Pda becomes PDA, etc)... if (!function_exists('format_table_name')) { function format_table_name($table, $pluralize = false, $stripunderscores = true, $strtoupper = false, $strtolower = true, $ucwords = true) { if ($stripunderscores) { $table = str_replace("_"," ",$table); } if ($strtoupper) { $table = strtoupper($table); } if ($strtolower) { $table = strtolower($table); } if ($pluralize) { $table .= "s"; $table = str_replace("mouses","mice",$table); $table = str_replace("softwares","software items",$table); } if ($ucwords) { $table = ucwords($table); $table = str_replace("Pc","PC",$table); $table = str_replace("Ram","RAM",$table); $table = str_replace("Cdrom","CDROM",$table); $table = str_replace("Pda","PDA",$table); $table = str_replace("Lan","LAN",$table); $table = str_replace("Nic","NIC",$table); $table = str_replace("Cpu","CPU",$table); $table = preg_replace("/CPU \(p/i","CPU (P",$table); $table = str_replace("Pen/d","Pen/D",$table); $table = str_replace("Allinone","All-In-One",$table); $table = str_replace("All-in-one","All-In-One",$table); $table = str_replace("Network Devices","Routers & Switches",$table); $table = str_replace("Network Device","Router & Switch",$table); $table = str_replace("Os","OS",$table); } return ($table); } } // Get CGPN alerts... if (!function_exists('get_alerts')) { function get_alerts($scope = "",$partnerid = "",$donorid = "",$userid = "",$alertid = "",$allseen = false) { global $userdata; global $user; //global $_SERVER['PHP_SELF']; //global $_SERVER; global $key; $userdata = $user->data; if ($scope) { $search .= "and (scope = '{$scope}') "; } if ($partnerid) { $search .= "and (partnerid = {$partnerid}) "; } if ($donorid) { $search .= "and (donorid = {$donorid}) "; } if ($userid) { $search .= "and (userid = {$userid}) "; } if ($alertid) { $search .= "and (id = {$alertid}) "; } // Get all alerts that pertain to this user... if (!$search) { // Generate partnerid query... $partnerid_result = my_db_query("SELECT * FROM `partner_passport_link` WHERE `phpbb_user_id` = {$user->data['user_id']}"); if (mysql_numrows($partnerid_result)) { $i = 0; while ($entry = mysql_fetch_assoc($partnerid_result)) { if ($where_partnerid && ($i < mysql_numrows($partnerid_result))) { $where_partnerid .= " || "; } $where_partnerid .= "partnerid = {$entry['partnerid']}"; $i++; } if ($where_partnerid) { $where_partnerid = "|| ({$where_partnerid})"; } } // Generate donorid query... if ($userdata['donorids'][0]) { $i = 0; foreach ($userdata['donorids'] as $donorid) { if ($where_donorid && ($i < sizeof($userdata['donorids']))) { $where_donorid .= " || "; } $where_donorid .= "donorid = {$donorid}"; $i++; } if ($where_donorid) { $where_donorid = "|| ({$where_donorid})"; } } if (preg_match("/proto/",$_SERVER['SERVER_NAME'])) { //echo "
USERDATA\n";
			//print_r($user->data);
			//echo "
\n"; //echo "my_db_query(\"select * from cgpn_alerts where 1 and ((scope = '' and partnerid = '' and donorid = '' and userid = '') || (scope != '' and partnerid = '' and donorid = '' and userid = '') {$where_partnerid} {$where_donorid} || (userid = {$userdata['user_id']}))\");
\n"; } $alerts_result = my_db_query("select * from cgpn_alerts where 1 and ((scope = '' and partnerid = '' and donorid = '' and userid = '') || (scope != '' and partnerid = '' and donorid = '' and userid = '') {$where_partnerid} {$where_donorid} || (userid = {$userdata['user_id']})) order by id desc"); if (mysql_numrows($alerts_result)) { while ($alerts = mysql_fetch_assoc($alerts_result)) { // Site-wide alerts... if (!$alerts['scope'] && !$alerts['partnerid'] && !$alerts['donorid'] && !$alerts['userid']) { if (is_array($master_alerts['system_alerts'])) { array_push($master_alerts['system_alerts'], $alerts); } else { $master_alerts['system_alerts'] = array($alerts); } // Scope-specific alerts... //} else if ($alerts['scope'] && !$alerts['partnerid'] && !$alerts['donorid'] && !$alerts['userid']) { } else if ($alerts['scope']) { if ($key) { $page = $key . ".html"; } else { $page = $_SERVER['REQUEST_URI']; } //if (eregi(trim(ereg_replace("/","",$page)),$alerts['scope']) || (substr($alerts['scope'],0,2) == "*:") || ($allseen)) { if (preg_match("/" . trim(str_replace("/","",$page) . "/i"),$alerts['scope']) || (substr($alerts['scope'],0,2) == "*:") || ($allseen)) { if (is_array($master_alerts['scope_alerts'])) { array_push($master_alerts['scope_alerts'], $alerts); } else { $master_alerts['scope_alerts'] = array($alerts); } } else { //echo "var " . rand() . " = '" . trim(ereg_replace("/","",$_SERVER['SCRIPT_URL'])) . " not found in {$alerts['scope']} and allseen = {$allseen}'\n"; } // Partner-specific alerts... } else if ($alerts['partnerid'] && !$alerts['userid']) { if (is_array($master_alerts['partner_alerts'])) { array_push($master_alerts['partner_alerts'], $alerts); } else { $master_alerts['partner_alerts'] = array($alerts); } // Donor-specific alerts... } else if ($alerts['donorid'] && !$alerts['userid']) { if (is_array($master_alerts['donor_alerts'])) { array_push($master_alerts['donor_alerts'], $alerts); } else { $master_alerts['donor_alerts'] = array($alerts); } // User-specific alerts... } else if ($alerts['userid']) { if (is_array($master_alerts['user_alerts'])) { array_push($master_alerts['user_alerts'], $alerts); } else { $master_alerts['user_alerts'] = array($alerts); } } } } // Get specific alert... } else { $alerts_result = my_db_query("select * from cgpn_alerts where 1 {$search}"); if (mysql_numrows($alerts_result)) { while ($alerts = mysql_fetch_assoc($alerts_result)) { if (!$alerts['scope'] && !$alerts['partnerid'] && !$alerts['donorid'] && !$alerts['userid']) { $array_key = "system_alerts"; } if ($alerts['scope']) { $array_key = "scope_alerts"; } if ($alerts['partnerid']) { $array_key = "partner_alerts"; } if ($alerts['donorid']) { $array_key = "donor_alerts"; } if ($alerts['userid']) { $array_key = "user_alerts"; } $master_alerts[$array_key] = array($alerts); } } } // Remove any seen alerts... $seen_result = my_db_query("select * from cgpn_alerts_seen where (userid = {$userdata['user_id']})"); if (mysql_numrows($seen_result)) { while ($alerts = mysql_fetch_assoc($seen_result)) { $seen[$alerts['alertid']] = $alerts; } if (sizeof($master_alerts)) { foreach ($master_alerts as $alertkey => $alerts) { foreach ($alerts as $alert) { if (!$seen[$alert['id']] && !$seen[$alert['id']]['show_again']) { // Go ahead and display this alert... if (is_array($return_alerts[$alertkey])) { array_push($return_alerts[$alertkey],$alert); } else { $return_alerts[$alertkey] = array($alert); } // Seen it, but see if they've asked to see it again... } else { if (($seen[$alert['id']]['show_again'] == "next_login") || $allseen) { // Compare sessions... if (($seen[$alert['id']]['session'] != $userdata['session_id']) || $allseen) { // Go ahead and display this alert... if (is_array($return_alerts[$alertkey])) { array_push($return_alerts[$alertkey],$alert); } else { $return_alerts[$alertkey] = array($alert); } } } else { //echo "\n"; } $alert['last_seen'] = $seen[$alert['id']]['displayed']; } } } } } else { $return_alerts = $master_alerts; } return($return_alerts); }} // Descriptive error output... if (!function_exists('error_out')) { function error_out($reason = "General Protection Fault

*chuckle*") { global $header_output_finished; $included_files = get_included_files(); $included_header = false; foreach($included_files as $filename) { if (preg_match("/header/i", $filename)) $included_header = true; } if ($included_header && $header_output_finished) { echo "
An Error Has Occurred:
\n"; echo "
$reason

\n"; include "/www/proto/includes/footer.inc"; } else { echo "
An Error Has Occurred:
\n"; echo "
$reason

\n"; //mail("ethan@cristina.org", "Cristina DEBUG " . $_SERVER['PHP_SELF'], $reason); //mail("brian@cristina.org", "Cristina DEBUG " . $_SERVER['PHP_SELF'], $reason); } exit(); }} // Calculate number of days between two dates... if (!function_exists('diff_days')) { function diff_days($start_date, $end_date) { return floor(abs(strtotime($start_date) - strtotime($end_date))/86400); }} if (!function_exists('kattare_encode')) { function kattare_encode($text, $pass = "Cr1sT1n@") { $level = 30; $key = ""; for ($i=0; $i<$level; $i++) { $mymd[$i] = md5(substr($pass,($i%strlen($pass)),1)); } for ($a=0; $a<32; $a++) for ($i=0; $i<$level; $i++) { $key .= substr($mymd[$i],$a,1); } for ($i=0; $i/",$from)) { $extract_from = explode("<",$from); $from_name = trim($extract_from[0]); $from_email = trim(strtolower(str_replace(">","",$extract_from[1]))); $output[] = "EXTRACTED FROM NAME: {$from_name}\nEXTRACTED FROM EMAIL: {$from_email}\n"; if ($from_name && $from_email) { $output[] = "SETTING setFrom({$from_email},{$from_name})\n"; $mail->setFrom($from_email, $from_name); } else { $output[] = "SETTING setFrom({$from})\n"; $mail->setFrom($from,""); } } else { $output[] = "NO FROM EXTRACTION NEEDED\n"; if (preg_match("/@/",$from)) { $output[] = "SETTING setFrom({$from})\n"; $mail->setFrom($from,""); } else { $output[] = "SETTING DEFAULT setFrom(\"webmaster@cristina.org\",\"Webmaster\");\n"; $mail->setFrom("webmaster@cristina.org","Webmaster"); } } // Set who the message is to be sent to... if (preg_match("//",$to)) { $extract_to = explode("<",$to); $to_name = trim($extract_to[0]); $to_email = trim(strtolower(str_replace(">","",$extract_to[1]))); $output[] = "EXTRACTED TO NAME: {$to_name}\nEXTRACTED TO EMAIL: {$to_email}\n"; if ($to_name && $to_email) { $output[] = "SETTING addAddress({$to_email},{$to_name})\n"; $mail->addAddress($to_email, $to_name); } else { $output[] = "SETTING addAddress({$to_email})\n"; $mail->addAddress($to,""); } } else { if (preg_match("/@/",$to)) { $output[] = "SETTING addAddress({$to})\n"; $mail->addAddress($to,""); } } // Set a carbon copy (CC) recipient... if ($cc) { if (preg_match("//",$cc)) { $extract_cc = explode("<",$cc); $cc_name = trim($extract_cc[0]); $cc_email = trim(strtolower(str_replace(">","",$extract_cc[1]))); $output[] = "EXTRACTED CC NAME: {$cc_name}\nEXTRACTED TO EMAIL: {$cc_email}\n"; if ($cc_name && $cc_email) { $output[] = "SETTING addCC({$cc_email},{$cc_name})\n"; $mail->addCC($cc_email, $cc_name); } else { $output[] = "SETTING addCC({$cc_email})\n"; $mail->addCC($cc,""); } } else { if (preg_match("/@/",$cc)) { $output[] = "SETTING addCC({$cc})\n"; $mail->addCC($cc,""); } } } // Set the subject line... $mail->Subject = $subject; // Set the main HTML message body... if ($body_html) { if ($embed_images) $mail->msgHTML(embed_images($body_html, $mail)); else $mail->msgHTML($body_html); } // Generate text-based email using lynx... if ($body_html && !$body_text) { $lynx_file = "/tmp/tmp-lynx-file-" . rand(10000,99999) . ".html"; $fw = fopen($lynx_file, "w"); fwrite($fw, $body_html); fclose($fw); $lynx_text = `/usr/bin/lynx -dump $lynx_file`; unlink($lynx_file); $lynx_text = preg_replace("/\[([0-9]{1,2})\]/", "(\\1) ", $lynx_text); // Replace the plain text body with one created manually... $mail->AltBody = $lynx_text; $output[] = "Message body TEXT set to Lynx output of HTML input\n"; // Or just use what's passed in... } else if ($body_text) { if (!$body_html) { $mail->isHTML(false); $mail->Body = $body_text; } else { $mail->AltBody = $body_text; } $output[] = "Message body TEXT set to supplied input\n"; } // Attach any uploaded files... if (!empty($attachments)) { if (!is_array($attachments)) $attachments = $attachments[] = $attachments; foreach ($attachments as $file) { if (file_exists($file)) { $mail->addAttachment($file); $output[] = "Attached File: {$file}\n"; } else { $output[] = "Failure attaching file to message: {$file}\nFile does not seem to exist!\n"; } } } // Finally, send the message... if (!$mail->send()) { $output[] = $mail->ErrorInfo; echo "Mailer Error: " . $mail->ErrorInfo; //echo "
\n" . print_r($output,true) . "
\n"; } // Process the blind carbon copy (Bcc)... if ($bcc) { $mail->ClearAddresses(); $mail->ClearCCs(); $mail->ClearBCCs(); ncf_mail($bcc, $from, $subject, $body_text, $body_html, "", "", $priority, $attachments); } return $output; }} if (!function_exists('embed_images')) { function embed_images(&$msg_body,$mail){ global $output; global $mail; // Get all img tags... preg_match_all('/]*src=[\'"]([^\'"]+)[\'"].*>/i', $msg_body, $matches); if (!isset($matches[0])) return; $output[] = sizeof($matches[0]) . " images found\n"; $embedded = array(); foreach ($matches[0] as $index => $img) { // make cid $id = 'img'.$index; $src_orig = $matches[1][$index]; $output[] = "Image found: {$src_orig}\n"; $src = str_replace("%20"," ",$matches[1][$index]); $local_src = str_replace("https://www.cristina.org","/www/proto",$src); if (!in_array($local_src,$embedded) && file_exists($local_src)) { $mail->AddEmbeddedImage($local_src,$id); $embedded[] = $src; $output[] = "Image embedded: {$local_src}\n"; } else { $output[] = "Image not found or already embeded: {$local_src}\n"; } // Finally, replace the src for the file in the msg_body... if (in_array($src,$embedded)) { $msg_body = str_replace($src_orig,'cid:'.$id, $msg_body); $output[] = "msg_body HTML updated with new source cid: {$id}\n"; } } return $msg_body; }} // // snags the mime type of a file on the local filesystem // if (!function_exists('mime_content_type')) { function mime_content_type ($f) { return trim(exec('file -bi ' . escapeshellarg($f))); }} // // sends mail for ncf using smtp... also handles image and file attachments // if (!function_exists('ncf_mail')) { function ncf_mail($to = "NCF Webmaster ", $from = "NCF Webmaster ", $subject = "Please set a subject...", $body_text = "", $body_html = "", $cc = "", $bcc = "", $priority = "", $attachments = "") { global $server_hostname; if ($server_hostname == "") { //$server_hostname = trim(`/usr/bin/cat /etc/HOSTNAME`); $server_hostname = $_SERVER["HTTP_HOST"]; } require_once "/www/proto/horde/pear/Mail.php"; // // smtp account to use // //$host = "mailout.cvo.cristina.org"; $host = "mail.cristina.org"; $username = "bbarrett"; $password = "redbear"; // // emulates Outlook hex date // $x = 0.0023283064365387; $y = 27111902.8329849; $epoch = time(); $hexdate = strtoupper(dechex(round((($epoch * $x) + $y)))); // // fix padded 0's // if (strlen($hexdate) == 7) { $hexdate = "0" . $hexdate; } elseif (strlen($hexdate) == 6) { $hexdate = "00" . $hexdate; } elseif (strlen($hexdate) == 5) { $hexdate = "00" . $hexdate; } // // test for html content // // I just don't see why we're doing this... if $body_html is present, it's got HTML... /* if ($body_html && (!stristr($body_html, '

') && !stristr($body_html, '
') && !stristr($body_html, ' '))) { $is_html = true; } */ $is_html = false; if ($body_html) { $is_html = true; } // // line out the envelope recipients // $recipients_tmp = stripslashes($to); if ($cc != "") $recipients_tmp .= "," . $cc; if ($bcc != "") $recipients_tmp .= "," . $bcc; preg_match_all("([a-zA-Z0-9._'-]*@[a-zA-Z0-9.-]*\.[a-zA-Z0-9.-]*)",$recipients_tmp,$regs); $recipients = implode(",", $regs[0]); if (!$is_html && (trim($attachments[0]) != "" || trim($attachments[1]))) { // it's a plain text message... $boundary_1 = "----=_NextPart_000_0001_" . $hexdate . ".8DCC78B0"; $header_content_type = "multipart/mixed;\n boundary=\"{$boundary_1}\""; $body = "This is a multi-part message in MIME format.\n\n"; $body .= "--{$boundary_1}\nContent-Type: text/plain;\n charset=\"us-ascii\"\nContent-Transfer-Encoding: 7bit\n\n"; $body .= $body_text . "\n\n"; // // attach any attachments passed in // for ($i = 0; $i 0) { $body .= "--{$boundary_1}--\n"; } } elseif (!$is_html) { // it's a plain text message... $header_content_type = "text/plain;\n charset=\"us-ascii\""; $headers['Content-Transfer-Encoding'] = "7bit"; $body = $body_text; } else { // it's an html message... // // add inline image(s)? // while(ereg("(http://([a-zA-Z0-9\/_.-]*)/([a-zA-Z0-9_.-]*)(.gif|.jpg|.jpeg|.png))", $body_html, $images)) { $images_to_attach[] = $images[1]; $images_to_attach_name[] = $images[3]; $images_to_attach_ext[] = $images[4]; $body_html = str_replace($images[1], "cid:" . $images[3], $body_html); } $boundary_1 = "----=_NextPart_000_0001_" . $hexdate . ".8DCC78B0"; $boundary_2 = "----=_NextPart_001_0002_" . $hexdate . ".8DCC78B0"; $header_content_type = "multipart/related;\n boundary=\"{$boundary_1}\""; $body = "This is a multi-part message in MIME format.\n\n"; $body .= "--{$boundary_1}\nContent-Type: multipart/alternative;\n boundary=\"{$boundary_2}\"\n\n\n"; $body .= "--{$boundary_2}\nContent-Type: text/plain;\n charset=\"us-ascii\"\nContent-Transfer-Encoding: 7bit\n\n"; if ($body_text != "") { $body .= $body_text . "\n\n"; } else { // $body .= "This message requires an HTML compliant email client to view.\n\n"; $lynx_file = "/tmp/tmp-lynx-file-" . rand(10000,99999) . ".html"; $fw = fopen($lynx_file, "w"); fwrite($fw, $body_html); fclose($fw); $lynx_text = `/usr/bin/lynx -dump $lynx_file`; unlink($lynx_file); $lynx_text = preg_replace("/\[([0-9]{1,2})\]/", "(\\1) ", $lynx_text); $body .= $lynx_text . "\n\n"; } $body .= "--{$boundary_2}\nContent-Type: text/html;\n charset=\"us-ascii\"\nContent-Transfer-Encoding: quoted-printable\n\n"; $body .= str_replace("

","\n

",quoted_printable_encode($body_html)) . "\n\n"; $body .= "--{$boundary_2}--\n\n"; // // attach any images detected above // for ($i = 0; $i\n\n"; $body .= $encoded_content . "\n"; } if (sizeof($images_to_attach) > 0) { $body .= "--{$boundary_1}--\n"; } // // attach any attachments passed in // for ($i = 0; $i 0) { $body .= "--{$boundary_1}--\n"; } } // // setup the headers // ereg("<([a-z0-9_.-]*@[a-z0-9.-]+\.[a-z]{2,4})>", $from, $regs); if (trim($regs[1]) != "") { $headers['Reply-To'] = $regs[1]; } else { $headers['Reply-To'] = $from; } $headers['From'] = $from; $headers['To'] = $to; if ($cc != "") { $headers['Cc'] = $cc; } if ($bcc != "") { $headers['Bcc'] = $bcc; } $headers['Subject'] = $subject; // // date format ... "Mon, 13 Nov 2006 15:42:22 -0800"; // $headers['Date'] = date("D, d M Y H:i:s O"); $headers['Organization'] = "National Cristina Foundation"; $headers['Message-ID'] = "<0000" . strtolower($hexdate) . "\$9befb8b0\$918a5946@" . $server_hostname . ">"; $headers['MIME-Version'] = "1.0"; $headers['Content-Type'] = $header_content_type; if ($priority == "1" || preg_match("/highest/i", $priority)) { $headers['X-Priority'] = "1 (Highest)"; } elseif ($priority == "2" || preg_match("/high/i", $priority)) { $headers['X-Priority'] = "2 (High)"; } elseif ($priority == "3" || preg_match("/normal/i", $priority)) { $headers['X-Priority'] = "3 (Normal)"; } elseif ($priority == "4" || preg_match("/low/i", $priority)) { $headers['X-Priority'] = "4 (Low)"; } elseif ($priority == "5" || preg_match("/lowest/i", $priority)) { $headers['X-Priority'] = "5 (Lowest)"; } $headers['X-Mailer'] = "Microsoft Office Outlook 11"; $headers['X-MimeOLE'] = "Produced By Microsoft MimeOLE V6.00.2900.2962"; // echo "
Sent headers:

";
	// print_r($headers);
	// echo "

\n"; // echo "
Sent body:
" . htmlentities($body) . "

\n"; // // send the message // $smtp = Mail::factory('smtp', array ('host' => $host, 'auth' => true, 'username' => $username, 'password' => $password)); $mail = $smtp->send($recipients, $headers, $body); if (PEAR::isError($mail)) { $GLOBALS['smtp_response'] = $mail->getMessage(); return false; } else { $GLOBALS['smtp_response'] = "Message successfully sent to: " . htmlentities($recipients); return true; } }} function my_get_headers($url) { $url_info=parse_url($url); if (isset($url_info['scheme']) && $url_info['scheme'] == 'https') { $port = 443; @$fp=fsockopen('ssl://'.$url_info['host'], $port, $errno, $errstr, 10); } else { $port = isset($url_info['port']) ? $url_info['port'] : 80; @$fp=fsockopen($url_info['host'], $port, $errno, $errstr, 10); } if($fp) { stream_set_timeout($fp, 10); $head = "HEAD ".@$url_info['path']."?".@$url_info['query']; $head .= " HTTP/1.0\r\nHost: ".@$url_info['host']."\r\n\r\n"; fputs($fp, $head); while(!feof($fp)) { if($header=trim(fgets($fp, 1024))) { $sc_pos = strpos( $header, ':' ); if( $sc_pos === false ) { $headers['status'] = $header; } else { $label = substr( $header, 0, $sc_pos ); $value = substr( $header, $sc_pos+1 ); $headers[strtolower($label)] = trim($value); } } } return $headers; } else { return false; } } /**universal * Encoder une chaine compatible "ENCODING=QUOTED-PRINTABLE" - cette chaine est décodable avec la fonction "quoted_printable_decode()" * ex: quoted_printable_encode(ut8_encode("c'est quand l'été ?")) -> "c'est quand l'=C3=A9t=C3=A9 ?" * * @author Thomas Pequet / Memotoo.com * @version 1.1 * @param string:string Chaine * @return Chaine encodée */ if (!function_exists('quoted_printable_encode')) { function quoted_printable_encode($string) { // Fonction qui ajoute au tableau de valeurs un "=" devant if (!function_exists("array_values_quoted_printable")) { function array_values_quoted_printable($tab) { $tabValues = array_values($tab); for ($i=0;$i "09", // "\n" => "0A", "\n" => "\n", "\r" => "0D", // " " => "20", "\xA0" => "A0", "¡" => "A1", "¢" => "A2", "£" => "A3", "¤" => "A4", "¥" => "A5", "¦" => "A6", "§" => "A7", "¨" => "A8", "©" => "A9", "ª" => "AA", "«" => "AB", "¬" => "AC", "®" => "AE", "¯" => "AF", "°" => "B0", "±" => "B1", "²" => "B2", "³" => "B3", "´" => "B4", "µ" => "B5", "¶" => "B6", "·" => "B7", "¸" => "B8", "¹" => "B9", "º" => "BA", "»" => "BB", "¼" => "BC", "½" => "BD", "¾" => "BE", "¿" => "BF", "À" => "C0", "Á" => "C1", "Â" => "C2", "Ã" => "C3", "Ä" => "C4", "Å" => "C5", "Æ" => "C6", "Ç" => "C7", "È" => "C8", "É" => "C9", "Ê" => "CA", "Ë" => "CB", "Ì" => "CC", "Í" => "CD", "Î" => "CE", "Ï" => "CF", "Ð" => "D0", "Ñ" => "D1", "Ò" => "D2", "Ó" => "D3", "Ô" => "D4", "Õ" => "D5", "Ö" => "D6", "×" => "D7", "Ø" => "D8", "Ù" => "D9", "Ú" => "DA", "Û" => "DB", "Ü" => "DC", "Ý" => "DD", "Þ" => "DE", "ß" => "DF", "à" => "E0", "á" => "E1", "â" => "E2", "ã" => "E3", "ä" => "E4", "å" => "E5", "æ" => "E6", "ç" => "E7", "è" => "E8", "é" => "E9", "ê" => "EA", "ë" => "EB", "ì" => "EC", "í" => "ED", "î" => "EE", "ï" => "EF", "ð" => "F0", "ñ" => "F1", "ò" => "F2", "ó" => "F3", "ô" => "F4", "õ" => "F5", "ö" => "F6", "÷" => "F7", "ø" => "F8", "ù" => "F9", "ú" => "FA", "û" => "FB", "ü" => "FC", "ý" => "FD", "þ" => "FE", "ÿ" => "FF", ); // Cas particulier -> remplacer tous les "=" en premier $string = str_replace("=", "=3D", $string); // Cas particulier de l'uft8 -> encodé en "quoted_printable" le caractère après "À", "Á", "Â", "Ã", "Ä", "Å" pour gérer tous les caractères autres que ceux ci-dessus (ex:"^" -> 0x88) $tailleTmp = strlen($string); $i = 0; while ($i<$tailleTmp) { if (($string[$i]=="À" || $string[$i]=="Á" || $string[$i]=="Â" || $string[$i]=="Ã" || $string[$i]=="Ä" || $string[$i]=="Å") && $i+1<$tailleTmp && $string[$i+1]!=" " && $string[$i+1]!="") { $strTmp = strtoupper(bin2hex($string[$i+1])); if (strlen($strTmp)==2) { // Décaler les caractères de 2 for ($j=$tailleTmp-1;$j>$i;$j--) { $string[$j+2] = $string[$j]; } // Remplacer par la valeur "quoted_printable" $string[$i+1] = "="; $string[$i+2] = $strTmp[0]; $string[$i+3] = $strTmp[1]; $i += 2; $tailleTmp += 2; } } $i++; } $string = str_replace(array_keys($tabStr), array_values_quoted_printable($tabStr), $string); return $string; }} // Determine if this pledge should be assigned a template... function matching_template($donorid, $sessionid, $partnerid) { // Load possible applications ordered by priority... $apply_result = my_db_query("select * from notify_applications order by priority asc"); $apply_num = mysql_numrows($apply_result); $j = 0; $l = 0; $matching_template = ""; $letter_template = ""; while ($j < $apply_num) { $apply_id = mysql_result($apply_result,$j,"id"); $apply_type = mysql_result($apply_result,$j,"type"); $apply_name = mysql_result($apply_result,$j,"name"); $apply_select = mysql_result($apply_result,$j,"table_select"); $apply_table = mysql_result($apply_result,$j,"table_name"); $apply_where = mysql_result($apply_result,$j,"table_where"); $apply_fields = mysql_result($apply_result,$j,"fields"); $apply_priority = mysql_result($apply_result,$j,"priority"); // Load all templates using this application... $template_result = my_db_query("select * from notify_templates where apply_to like '$apply_type' order by id desc"); $template_num = mysql_numrows($template_result); $k = 0; while ($k < $template_num) { $template_name = mysql_result($template_result,$k,"name"); $fields = explode(":",mysql_result($template_result,$k,"fields")); $values = explode(":",mysql_result($template_result,$k,"values")); // Create basic application query... $query = "select $apply_select from $apply_table where $apply_where limit 1"; // Swap in template specific variables... $m = 0; while ($m < sizeof($fields) && $fields[$m]) { $this_field = $fields[$m]; $this_value = $values[$m]; if ($this_field && $this_value) { //echo "Replacing {$this_field} with {$this_value}...\n"; //$debug_output .="Replacing $this_field with $this_value...

\n"; $query = preg_replace("/\[$this_field\]/",$this_value,$query); } $m++; } // Swap in pledge specific variables including sessionid, partnerid... $query = preg_replace("/\[partnerid\]/i",$partnerid,preg_replace("/\[sessionid\]/i",$sessionid,preg_replace("/\[donorid\]/i",$donorid,$query))); //$GLOBALS['debug_output'] .= "my_db_query(\"cristina\" , \"$query\");

\n"; //echo "Executing template query: my_db_query(\"cristina\" , \"$query\");\n"; // Now see if executing the query results in a match... $check_result = my_db_query("$query"); $check_num = mysql_numrows($check_result); if ($check_num > 0) { $matching_template = $template_name; echo "Template Match: {$matching_template}\n"; return $matching_template; $GLOBALS['debug_output'] .="

Template Match! DONORID: {$donorid} SESSIONID: {$sessionid} matches the $matching_template template.\n"; } else { //$GLOBALS['debug_output'] .="

Application match not found for query: {$query}

\n"; } $k++; } $j++; } //echo "No matching template found... use default\n"; $default_template = "Default Schedule"; return $default_template; } /* * DESCRIPTION * * This script includes the getGeo() function that uses the Google/Yahoo Maps API to * ellicit lat/long data for a supplied address. * * * required: * * donorid/partnerid ID record to lookup * database Tells the function whether to use cristina or cristina_tmp * table Which table should the function look for / update address info * * optional: * * update Whether to update the database with found lat/lon (TRUE/FALSE) * * global: * * precision To what level of detail did the Geo service make a match? * Possible matches include: * Google (0 - 9) 9 bldg, 8 address, 7 street, and so on... * Yahoo (state,city,zip+2,zip+4,street,address) More? * lat Found latitude (e.g. 40.023571) * lon Found longitude (e.g. -98.07122) */ function getGeo($donorid,$partnerid,$sessionid,$locationid,$database,$table,$update) { //$GLOBALS['debug'] = true; global $find_loc; if ($GLOBALS['debug']) { echo "\n"; } $contact_array = false; if (is_array($donorid)) { // ok, so donorid is misleading, for the dsf3 we needed to take in an array that is all of the donor info $address1 = $donorid['address1']; $address2 = $donorid['address2']; $city = $donorid['city']; $state = $donorid['state']; $country = $donorid['country']; $region = $donorid['region']; // Alternative equipment location specified, get lat/lon for that as well... if ($donorid['equip_address1'] && $donorid['equip_city'] && $donorid['equip_state']) { $equip_address1 = $donorid['equip_address1']; $equip_address2 = $donorid['equip_address2']; $equip_city = $donorid['equip_city']; $equip_state = $donorid['equip_state']; $equip_country = $donorid['equip_country']; $equip_region = $donorid['equip_region']; } unset($donorid); $contact_array = true; // Get address information for partners... } elseif ($table == "partner_info" || $table == "partner_info_temp") { $partner = get_partner_array($partnerid,$projectid,$locationid); $org_name = $partner['org_name']; $main_locationid = $partner['main_locationid']; foreach ($partner['project_details'] as $project) { if (is_array($project['locations'][$main_locationid])) { $location = $project['locations'][$main_locationid]; $address1 = $location['address1']; $address2 = $location['address2']; $city = $location['city']; $state = $location['state']; $region = $location['region']; $country = $location['country']; if (preg_match("/United States/i",$country)) { $zip = explode("-",$location['zip']); $zip = $zip[0]; } else { $zip = $location['zip']; } } } } else if ($table == "partner_locations") { if (!$locationid) { //$location_result = my_db_query("SELECT * FROM partner_locations WHERE (partnerid = {$partnerid}) AND (location_type like 'main')"); $location_result = my_db_query("SELECT partner_locations.* FROM partner_locations_link LEFT JOIN partner_locations ON partner_locations.id = partner_locations_link.locationid WHERE (partner_locations_link.partnerid = {$partnerid}) AND (partner_locations_link.projectid = '')"); } else { //echo "\n"; $location_result = my_db_query("SELECT * FROM partner_locations WHERE (id = {$locationid})"); } if (mysql_numrows($location_result)) { $id = mysql_result($location_result,0,"id"); //echo "\n"; $link_result = my_db_query("SELECT * FROM `partner_locations_link` WHERE (`locationid` = {$id})"); if (mysql_numrows($link_result)) { $projectid = mysql_result($link_result,0,"projectid"); } if ($GLOBALS['find_loc']) { $lat = mysql_result($location_result,0,"lat"); $lon = mysql_result($location_result,0,"lon"); echo "\n"; } $address1 = mysql_result($location_result,0,"address1"); $address2 = mysql_result($location_result,0,"address2"); $city = mysql_result($location_result,0,"city"); $state = mysql_result($location_result,0,"state"); $country = mysql_result($location_result,0,"country"); $region = mysql_result($location_result,0,"region"); if (preg_match("/United States/i",$country)) { $zip = explode("-",mysql_result($location_result,0,"zip")); $zip = $zip[0]; } else { $zip = mysql_result($location_result,0,"zip"); } } } else if ($table == "donor_info" || $table == "donor_info_temp") { $donor_result = my_db_query("select id, donorid, name, addy1, addy2, city, state, zip, country, region, lat, lon from {$table} where (addy1 not like '' and city not like '' and zip not like '' and (donorid like '{$donorid}'))","{$database}"); $donor_num = mysql_numrows($donor_result); if ($donor_num > 0) { $id = mysql_result($donor_result,$i,"id"); $donorid = mysql_result($donor_result,$i,"donorid"); $name = mysql_result($donor_result,$i,"name"); $address1 = mysql_result($donor_result,$i,"addy1"); $address2 = mysql_result($donor_result,$i,"addy2"); $city = mysql_result($donor_result,$i,"city"); $state = mysql_result($donor_result,$i,"state"); $country = mysql_result($donor_result,$i,"country"); $region = mysql_result($donor_result,$i,"region"); if (preg_match("/United States/i",$country)) { $zip = explode("-",mysql_result($donor_result,$i,"zip")); $zip = $zip[0]; } else { $zip = mysql_result($donor_result,$i,"zip"); } $lat = mysql_result($donor_result,$i,"lat"); $lon = mysql_result($donor_result,$i,"lon"); } // Determine whether to use the donor's address, the asset contact or an equipment contact address... $asset_result = my_db_query("select * from asset_contact where donorid like '$donorid' and sessionid like '$sessionid'"); $asset_num = mysql_numrows($asset_result); if ($asset_num > 0) { $equip_loc = mysql_result($asset_result,0,"equip_loc"); if ($equip_loc == "asset_contact") { $id = mysql_result($asset_result,$i,"id"); $address1 = mysql_result($asset_result,0,"addy1"); $address2 = mysql_result($asset_result,0,"addy2"); $city = mysql_result($asset_result,0,"city"); $state = mysql_result($asset_result,0,"state"); $zip = mysql_result($asset_result,0,"zip"); $country = mysql_result($asset_result,0,"country"); $region = mysql_result($asset_result,0,"region"); $lat = mysql_result($asset_result,0,"lat"); $lon = mysql_result($asset_result,0,"lon"); $table = "asset_contact"; } } // Equipment resides with the equipment contact... if (($equip_loc == "equip_contact") || !$equip_loc) { $equip_result = my_db_query("select * from equip_contact where donorid like '$donorid' and sessionid like '$sessionid'"); $equip_num = mysql_numrows($equip_result); if ($equip_num > 0) { $id = mysql_result($equip_result,$i,"id"); $address1 = mysql_result($equip_result,0,"addy1"); $address2 = mysql_result($equip_result,0,"addy2"); $city = mysql_result($equip_result,0,"city"); $state = mysql_result($equip_result,0,"state"); $zip = mysql_result($equip_result,0,"zip"); $country = mysql_result($equip_result,0,"country"); $region = mysql_result($equip_result,0,"region"); $lat = mysql_result($equip_result,0,"lat"); $lon = mysql_result($equip_result,0,"lon"); $table = "equip_contact"; } } } //$GLOBALS['debug'] = true; if ((!$lat || !$lon) || $update) { $search_address = urlencode($address1) . ",+"; $search_city = urlencode($city) . ",+"; $search_state = urlencode($state); $search_zip = urlencode($zip) . "+"; $search_country = urlencode($country); $search_region = urlencode($region) . ",+"; if ($equip_address1 && $equip_city && ($equip_state || $equip_region)) { $equip_search_address = urlencode($equip_address1) . ",+"; $equip_search_city = urlencode($equip_city) . ",+"; $equip_search_state = urlencode($equip_state); $equip_search_zip = urlencode($equip_zip) . "+"; $equip_search_country = urlencode($equip_country); $equip_search_region = urlencode($equip_region) . ",+"; } // The Yahoo! Web Services request (5,000/IP/day)... $yahoo_req = "http://where.yahooapis.com/geocode?location={$search_address}{$search_city}{$search_state}%20{$search_zip}&flags=P&appid=eeMHdi6s"; // Old Google (browser) Key... //$key = "AIzaSyC3UIKTacidH10XUDu7ouzygy7B5xGfkdY"; // New browser key (doesn't seem necessary with v3?)... $key = "AIzaSyCTQcPgpBM5NILpj74wC_F0-O27yT0sY2A"; // IP Server key... //$key = "AIzaSyDO0irzkD90G1VuCi1bUzb6WPJWhBVsbfc"; if (preg_match("/United States/i",$country)) { if ($GLOBALS['debug']) { echo "\n"; } //$req1 = "https://maps.google.com/maps/api/geocode/json?sensor=false&key=AIzaSyCTQcPgpBM5NILpj74wC_F0-O27yT0sY2A&address= $req1 = "https://maps.googleapis.com/maps/api/geocode/json?address={$search_address}{$search_city}{$search_state}+{$search_zip}&key={$key}&sensor=false&random=" . rand(); if ($equip_search_address) { $req2 = "https://maps.googleapis.com/maps/api/geocode/json?address={$equip_search_address}{$equip_search_city}{$equip_search_state}+{$equip_search_zip}&key={$key}&sensor=false&random=" . rand(); } } else if (preg_match("/Canada/i",$country)) { if ($GLOBALS['debug']) { echo "\n"; } if ($search_region) { $req1 = "https://maps.googleapis.com/maps/api/geocode/json?address={$search_address}{$search_city}{$search_region}{$search_zip}{$search_country}&key={$key}&sensor=false&random=" . rand(); if ($equip_search_address) { $req2 = "https://maps.googleapis.com/maps/api/geocode/json?address={$equip_search_address}{$equip_search_city}{$equip_search_region}{$equip_search_zip}{$equip_search_country}&key={$key}&sensor=false&random=" . rand(); } } else { $req1 = "https://maps.googleapis.com/maps/api/geocode/json?address={$search_address}{$search_city}{$search_zip}{$search_country}&key={$key}&sensor=false&random=" . rand(); if ($equip_search_address) { $req2 = "https://maps.googleapis.com/maps/api/geocode/json?address={$equip_search_address}{$equip_search_city}{$equip_search_zip}{$equip_search_country}&key={$key}&sensor=false&random=" . rand(); } } } else { if ($GLOBALS['debug']) { echo "\n"; } if ($search_region) { $req1 = "https://maps.googleapis.com/maps/api/geocode/json?address={$search_address}{$search_city}{$search_region}{$search_zip},+{$search_country}&key={$key}&sensor=false&random=" . rand(); if ($equip_search_address) { $req2 = "https://maps.googleapis.com/maps/api/geocode/json?address={$equip_search_address}{$equip_search_city}{$equip_search_region}{$equip_search_zip},+{$equip_search_country}&key={$key}&sensor=false&random=" . rand(); } } else { $req1 = "https://maps.googleapis.com/maps/api/geocode/json?address={$search_address}{$search_city}{$search_zip},+{$search_country}&key={$key}&sensor=false&random=" . rand(); if ($equip_search_address) { $req2 = "https://maps.googleapis.com/maps/api/geocode/json?address={$equip_search_address}{$equip_search_city}{$equip_search_zip},+{$equip_search_country}&key={$key}&sensor=false&random=" . rand(); } } } if ($GLOBALS['debug']) { echo "\n"; } // Make the request (Yahoo)... //$phpserialized = file_get_contents($req); // Google Maps API v3 Service request (2,500/IP/day)... $request = file_get_contents($req1); $map_json = json_decode($request, true); $GLOBALS['lat'] = $map_json['results'][0]['geometry']['location']['lat']; $GLOBALS['lon'] = $map_json['results'][0]['geometry']['location']['lng']; $GLOBALS['precision'] = $map_json['results'][0]['types'][0]; if ($GLOBALS['debug']) echo "\n"; if ($GLOBALS['debug']) echo "\n"; // Equipment address specified, find that... if ($req2) { $request = file_get_contents($req2); $equip_map_json = json_decode($request, true); $GLOBALS['equip_lat'] = $equip_map_json['results'][0]['geometry']['location']['lat']; $GLOBALS['equip_lon'] = $equip_map_json['results'][0]['geometry']['location']['lng']; $GLOBALS['equip_precision'] = $equip_map_json['results'][0]['types'][0]; if ($GLOBALS['debug']) echo "\n"; } // Bad precision, try to get the address using the address2 field... if (($GLOBALS['precision'] != "street_address" && $GLOBALS['precision'] != "premise" && $GLOBALS['precision'] != "subpremise") && $address2 && !$GLOBALS['find_loc']) { $search_address = urlencode(trim($address2)); $req2 = "https://maps.googleapis.com/maps/api/geocode/json?address={$search_address},+{$search_city}{$search_state}+{$search_zip}&key=&sensor=false&random=" . rand(); $request = file_get_contents($req2); $map_json = json_decode($request, true); $GLOBALS['lat'] = $map_json['results'][0]['geometry']['location']['lat']; $GLOBALS['lon'] = $map_json['results'][0]['geometry']['location']['lng']; $GLOBALS['precision'] = $map_json['results'][0]['types'][0]; if ($GLOBALS['debug']) { echo "\n"; } if ($GLOBALS['debug']) { echo "\n"; } if ($GLOBALS['debug']) echo "\n"; } if ($equip_search_address && ($GLOBALS['equip_precision'] != "street_address" && $GLOBALS['equip_precision'] != "premise" && $GLOBALS['equip_precision'] != "subpremise")) { $search_address = urlencode(trim($equip_address2)); $req2 = "https://maps.googleapis.com/maps/api/geocode/json?address={$search_address},+{$search_city}{$search_state}+{$search_zip}&key=&sensor=false&random=" . rand(); $request = file_get_contents($req2); $equip_map_json = json_decode($request, true); $GLOBALS['equip_lat'] = $equip_map_json['results'][0]['geometry']['location']['lat']; $GLOBALS['equip_lon'] = $equip_map_json['results'][0]['geometry']['location']['lng']; $GLOBALS['equip_precision'] = $equip_map_json['results'][0]['types'][0]; if ($GLOBALS['debug']) { echo "\n"; } if ($GLOBALS['debug']) { echo "\n"; } if ($GLOBALS['debug']) echo "\n"; } // Parse the serialized response (Yahoo)... //$phparray = unserialize($phpserialized); // Pull Yahoo data from array... //$precision = $phparray['ResultSet']['Result']['precision']; //$lon = $phparray['ResultSet']['Result']['Longitude']; //$lat = $phparray['ResultSet']['Result']['Latitude']; // Only update the database if we have street or address precision and update was called for... if (($GLOBALS['precision'] == "street_address" || $GLOBALS['precision'] == "premise" || $GLOBALS['precision'] == "subpremise") && $GLOBALS['lat'] && $GLOBALS['lon'] && !$GLOBALS['find_loc'] && $update) { if ($GLOBALS['debug']) { echo "\n"; } my_db_query("update {$table} set lat = '{$GLOBALS['lat']}', lon = '{$GLOBALS['lon']}' where id like '$id'","{$database}"); } else if (!$contact_array && $table && ($table_name == "partner_locations")) { if ($GLOBALS['debug']) { echo "\n"; } my_db_query("update {$table} set `set_manually` = '', `lat` = '', `lon` = '' where id like '$id'","{$database}"); } } else { echo "\n"; $GLOBALS['lat'] = $lat; $GLOBALS['lon'] = $lon; } // Return geo data (Yahoo)... //return $phparray; // Return geo data (Google)... return $map_json; } function get_donor_array($donorid, $sessionid = "", $use_temp_data = false) { if ($use_temp_data) { $db = "cristina_tmp"; } else { $db = "cristina"; } $donor_result = my_db_query("SELECT * FROM donor_info WHERE donorid = $donorid","{$db}"); $donor_info = mysql_fetch_array($donor_result); // echo "Donor Record Found: {$donor_info['name']}\n"; $donor['donor_id'] = $donorid; $donor['donor_name'] = $donor_info['name']; $donor['donor_company'] = $donor_info['company']; $donor['donor_email'] = $donor_info['email']; $donor['donor_addy1'] = $donor_info['addy1']; $donor['donor_addy2'] = $donor_info['addy2']; $donor['donor_zip'] = $donor_info['zip']; $donor['donor_city'] = $donor_info['city']; $donor['donor_state'] = $donor_info['state']; $donor['donor_country'] = $donor_info['country']; $donor['donor_region'] = $donor_info['region']; $donor['donor_phone_area'] = $donor_info['area']; $donor['donor_phone_prefix'] = $donor_info['phone_prefix']; $donor['donor_phone_suffix'] = $donor_info['phone_suffix']; $donor['donor_phone_ext'] = $donor_info['phone_ext']; $donor['donor_fax_area'] = $donor_info['fax_area']; $donor['donor_fax_prefix'] = $donor_info['fax_prefix']; $donor['donor_fax_suffix'] = $donor_info['fax_suffix']; $donor['lat'] = $donor_info['lat']; $donor['lon'] = $donor_info['lon']; $donor['donor_phone'] = "({$donor_info['area']}) {$donor_info['phone_prefix']}-{$donor_info['phone_suffix']}"; if ($donor_info['fax_area'] && $donor_info['fax_prefix'] && $donor_info['fax_suffix']) { $donor['donor_fax'] = "({$donor_info['fax_area']}) {$donor_info['fax_prefix']}-{$donor_info['fax_suffix']}"; } else { $donor['donor_fax'] = ""; } // // generate possibly helpful contact info text // $donor['donor_contact_text'] = "{$donor['donor_name']}\n"; if ($donor['donor_company']) { $donor['donor_contact_text'] .= "{$donor['donor_company']}\n"; } $donor['donor_contact_text'] .= "{$donor['donor_addy1']}\n"; if ($donor['donor_addy2']) { $donor['donor_contact_text'] .= "{$donor['donor_addy2']}\n"; } $donor['donor_contact_text'] .= "{$donor['donor_city']}, {$donor['donor_state']} {$donor['donor_zip']}\n"; if ($donor['donor_region']) { $donor['donor_contact_text'] .= "{$donor['donor_region']}\n"; } $donor['donor_contact_text'] .= "{$donor['donor_country']}\n"; $donor['donor_contact_text'] .= "\nPhone: {$donor['donor_phone']}\n"; if ($donor['donor_fax']) { $donor['donor_contact_text'] .= "Fax: {$donor['donor_fax']}\n"; } if ($donor['donor_email']) { $donor['donor_contact_text'] .= "Email: {$donor['donor_email']}\n"; } // Which staff member typically deals with this US donor? $region_result = my_db_query("select user from regions where state = '{$donor['donor_state']}'"); $region_num = mysql_numrows($region_result); if ($region_num > 0) { $user = mysql_fetch_assoc($region_result); $staff_result = my_db_query("select name, extension from dtap_settings where user = '{$user['user']}'"); $staff_num = mysql_numrows($staff_result); if ($staff_num > 0) { $staff = mysql_fetch_assoc($staff_result); $donor['staff_user'] = $user['user']; $donor['staff_name'] = $staff['name']; $donor['staff_ext'] = $staff['extension']; } // Must not be in the US... } else { // Default to Nancy for International partners... $donor['staff_user'] = "nancy"; $donor['staff_name'] = "Nancy Cortez"; $donor['staff_ext'] = "364"; } // No session specified, get all past donation information... if ($sessionid == "") { $session_where = ""; } else { $session_where = "AND (`sessionid` like '{$sessionid}')"; } if (!$use_temp_data) { $db = "cristina"; } else { $db = "cristina_tmp"; } // Get basic session information from donation_summary... //echo "my_db_query(\"select distinct sessionid, status, DATE(donation_summary.match_date) as match_date, DATE(donation_summary.placement_date) as placement_date, DATE(donation_summary.date) as pledge_date from donation_summary where donorid = '{$donorid}' {$session_where}\",$db);\n"; $sessions_result = my_db_query("select distinct `projectid`, `locationid`, `will_ship`, `region_code`, sessionid, status, DATE(donation_summary.match_date) as match_date, DATE(donation_summary.placement_date) as placement_date, DATE(donation_summary.date) as pledge_date from donation_summary where donorid = '{$donorid}' {$session_where}",$db); $sessions_num = mysql_numrows($sessions_result); while ($session = mysql_fetch_assoc($sessions_result)) { $donor['sessionids'][$session['sessionid']] = $session; $session_result = my_db_query("SELECT `table_name`, `itemid`, `option_level`, `status` FROM `donation_summary` WHERE (`donorid` = {$donorid}) AND (`sessionid` like '{$session['sessionid']}')",$db); if (mysql_numrows($session_result)) { while ($items = mysql_fetch_assoc($session_result)) { if (!is_array(${$items['table_name']})) { $options_result = my_db_query("SELECT * FROM `form_options` WHERE (`table_name` like '{$items['table_name']}') AND (`display_when` = {$items['option_level']}) AND (`hidden` < 1) ORDER BY `field_name`,`sort_order` ASC"); if (mysql_numrows($options_result)) { while ($options = mysql_fetch_assoc($options_result)) { ${$items['table_name']}[$options['field_name']][$options['option_value']] = $options['option_text']; } } } //echo "

" . print_r(${$items['table_name']},true) . "
\n"; $item_result = my_db_query("SELECT * FROM `{$items['table_name']}` WHERE (`id` = {$items['itemid']})",$db); if (mysql_numrows($item_result)) { $key = $items['table_name'] . "-" . $items['itemid']; $item = mysql_fetch_assoc($item_result); foreach ($item as $field => $value) { if (is_numeric($value) && ${$items['table_name']}[$field][$value]) { $value = ${$items['table_name']}[$field][$value]; } $donor['sessionids'][$session['sessionid']]['items'][$key][$field] = $value; } } } } } $asset = array(); $equip = array(); // Get all equip_contact entries for this donor... $equip_result = my_db_query("SELECT * FROM equip_contact WHERE donorid = '$donorid' {$session_where}"); while ($equip_info = mysql_fetch_array($equip_result,MYSQLI_ASSOC)) { $this_sessionid = $equip_info['sessionid']; // Generate the unified phone field... if ($equip_info['area'] && $equip_info['phone_prefix'] && $equip_info['phone_suffix']) { $equip_info['phone'] = "({$equip_info['area']}) {$equip_info['phone_prefix']}-{$equip_info['phone_suffix']}"; } else { $equip_info['phone'] = ""; } // Generate the unified fax field... if ($equip_info['fax_area'] && $equip_info['fax_prefix'] && $equip_info['fax_suffix']) { $equip_info['fax'] = "({$equip_info['fax_area']}) {$equip_info['fax_prefix']}-{$equip_info['fax_suffix']}"; } else { $equip_info['fax'] = ""; } $equip_keys = array_keys($equip_info); $equip_values = array_values($equip_info); // Go through all fields and prepend "equip_" to the field name... for ($a = 0;$a < sizeof($equip_keys);$a++) { $new_key = "equip_" . $equip_keys[$a]; $equip[$this_sessionid][$new_key] = $equip_values[$a]; } // If this session has asset_contact data, merge with it and update the master array... if (array_key_exists($this_sessionid, $asset)) { $donor['sessionids'][$this_sessionid] = array_merge_recursive($asset[$this_sessionid], $equip[$this_sessionid]); } else { $donor['sessionids'][$this_sessionid] = array_merge_recursive($donor['sessionids'][$this_sessionid],$equip[$this_sessionid]); } // Overwrite main donor record lat/lon with equipment address coordinates... if ($equip_info['lat'] && $equip_info['lon']) { $donor['lat'] = $equip_info['lat']; $donor['lon'] = $equip_info['lon']; } } // Get all asset_contact entries for this donor... $asset_result = my_db_query("SELECT * FROM asset_contact WHERE donorid = '$donorid' {$session_where}"); $asset_info = mysql_fetch_array($asset_result); while ($asset_info = mysql_fetch_array($asset_result,MYSQLI_ASSOC)) { $this_sessionid = $asset_info['sessionid']; // Generate the unified phone field... if ($asset_info['area'] && $asset_info['phone_prefix'] && $asset_info['phone_suffix']) { $asset_info['phone'] = "({$asset_info['area']}) {$asset_info['phone_prefix']}-{$asset_info['phone_suffix']}"; } else { $asset_info['phone'] = ""; } // Generate the unified fax field... if ($asset_info['fax_area'] && $asset_info['fax_prefix'] && $asset_info['fax_suffix']) { $asset_info['fax'] = "({$asset_info['fax_area']}) {$asset_info['fax_prefix']}-{$asset_info['fax_suffix']}"; } else { $asset_info['fax'] = ""; } $asset_keys = array_keys($asset_info); $asset_values = array_values($asset_info); // Go through all fields and prepend "asset_" to the field name... for ($a = 0;$a < sizeof($asset_keys);$a++) { $new_key = "asset_" . $asset_keys[$a]; $asset[$this_sessionid][$new_key] = $asset_values[$a]; } // If this session has equip_contact data, merge with it and update the master array... if (array_key_exists($this_sessionid, $equip)) { $donor['sessionids'][$this_sessionid] = array_merge_recursive($asset[$this_sessionid], $equip[$this_sessionid]); } else { if (!is_array($donor['sessionids'][$this_sessionid])) $donor['sessionids'][$this_sessionid] = array(); $donor['sessionids'][$this_sessionid] = array_merge_recursive($donor['sessionids'][$this_sessionid],$asset[$this_sessionid]); } } // Create and/or pad any remaining sessions... /* while ($this_session = mysql_fetch_array($sessions_result)) { if (!is_array($donor['sessionids'])) { $donor['sessionids'] = array(); } if (!array_key_exists($this_session['sessionid'],$donor['sessionids'])) { $donor['sessionids'][$this_session['sessionid']] = array(); } $donor['sessionids'][$this_session['sessionid']]['pledge_date'] = $this_session['pledge_date']; $donor['sessionids'][$this_session['sessionid']]['match_date'] = $this_session['match_date']; $donor['sessionids'][$this_session['sessionid']]['placement_date'] = $this_session['placement_date']; $donor['sessionids'][$this_session['sessionid']]['status'] = $this_session['status']; } */ // Look for any donations begun but not complete by this donor... //} else if ($use_temp_data) { $tmp_donor_result = my_db_query("SELECT * FROM `donor_info` WHERE (TO_DAYS(NOW()) - TO_DAYS(`submission_date`) < 180) and (`donorid` like '{$donor_info['donorid']}' || `email` like '" . mysql_escape_string($donor_info['email']) . "') order by `submission_date` desc","cristina_tmp"); while ($donations = mysql_fetch_assoc($tmp_donor_result)) { $donor['in_progress'][$donations['sessionid']] = $donations; } // sessionid was passed, get specific info... /* $equip_contact_exists = false; if ($sessionid != "") { $equip_result = my_db_query("SELECT * FROM equip_contact WHERE donorid = '$donorid' and sessionid = '$sessionid'"); $equip_num = mysql_numrows($equip_result); if ($equip_num > 0) { $equip_contact_exists = true; $equip_info = mysql_fetch_array($equip_result); $donor['equip_name'] = $equip_info['name']; $donor['equip_addy1'] = $equip_info['addy1']; $donor['equip_addy2'] = $equip_info['addy2']; $donor['equip_zip'] = $equip_info['zip']; $donor['equip_city'] = $equip_info['city']; $donor['equip_state'] = $equip_info['state']; $donor['equip_country'] = $equip_info['country']; $donor['equip_region'] = $equip_info['region']; $donor['equip_phone'] = "({$equip_info['area']}) {$equip_info['phone_prefix']}-{$equip_info['phone_suffix']}"; if ($equip_info['fax_area'] && $equip_info['fax_prefix'] && $equip_info['fax_suffix']) { $donor['equip_fax'] = "({$equip_info['fax_area']}) {$equip_info['fax_prefix']}-{$equip_info['fax_suffix']}"; } else { $donor['equip_fax'] = ""; } } } */ // Why are we doing this? /* if (!$equip_contact_exists) { $donor['equip_name'] = $donor['donor_name']; $donor['equip_addy1'] = $donor['donor_addy1']; $donor['equip_addy2'] = $donor['donor_addy2']; $donor['equip_zip'] = $donor['donor_zip']; $donor['equip_city'] = $donor['donor_city']; $donor['equip_state'] = $donor['donor_state']; $donor['equip_country'] = $donor['donor_country']; $donor['equip_region'] = $donor['donor_region']; $donor['equip_phone'] = $donor['donor_phone']; $donor['equip_fax'] = $donor['donor_fax']; } */ //echo "\n"; return $donor; } function get_partner_search_query($preset = '', $status = 'active', $state = '', $date_begin = '', $date_end = '') { if ($preset != "") { $result = my_db_query("SELECT * FROM search_presets WHERE id = $preset"); if (mysql_num_rows($result) != 0) { $query_info = mysql_fetch_assoc($result); $query = $query_info['query']; } else { $query = "SELECT DISTINCT partner_info.id as id,partner_info.org_name as org_name FROM partner_info LEFT JOIN partner_locations ON partner_info.id = partner_locations.partnerid WHERE partner_info.status LIKE '-STATUS-' -STATE- ORDER BY partner_info.id"; } } else { $query = "SELECT DISTINCT partner_info.id as id,partner_info.org_name as org_name FROM partner_info LEFT JOIN partner_locations ON partner_info.id = partner_locations.partnerid WHERE partner_info.status LIKE '-STATUS-' -STATE- ORDER BY partner_info.id"; } // status $query = str_replace("-STATUS-", $status, $query); // local (state/prov) if ($state != "") { $state_arr = split(",", $state); unset($state); foreach ($state_arr as $this_state) { if (trim($this_state) != "") { if ($state != "") $state .= ","; $state .= "'{$this_state}'"; } } if ($state != "") { $state_str = "AND partner_locations.state IN ({$state})"; } } $query = str_replace("-STATE-", $state_str, $query); // date begin if ($date_begin != "") { $date_begin_epoch = strtotime($date_begin); if ($query_info['date_format'] == "epoch") $this_date = $date_begin_epoch; else $this_date = date("{$query_info['date_format']}", $date_begin_epoch); } $query = str_replace("-DATE_BEGIN-", $this_date, $query); // date end if ($date_end != "") { $date_end_epoch = strtotime($date_end); if ($query_info['date_format'] == "epoch") $this_date = $date_end_epoch; else $this_date = date("{$query_info['date_format']}", $date_end_epoch); } $query = str_replace("-DATE_END-", $this_date, $query); return $query; } function get_partner_array($partnerid, $projectid = "", $locationid = "", $db = "cristina") { // Just die if they try passing in a non-numeric partnerID or projectid... if (!is_numeric($partnerid)) exit; if ($projectid) { if (!is_numeric($projectid) && ($projectid != "all")) exit; } $result = my_db_query("SELECT * FROM `partner_info` WHERE (`id` = '" . mysql_escape_string($partnerid) . "')", $db); $partner_num = mysql_numrows($result); if ($partner_num > 0) { $partner_info = mysql_fetch_array($result); // echo "Partner Record Found: {$partner_info['org_name']}\n"; $partner['partnerid'] = $partner_info['id']; $partner['partner_id'] = $partner_info['id']; $partner['partner_parent_id'] = $partner_info['parent_id']; if ($db == "cristina_tmp") { $partner['signup_name'] = $partner_info['signup_name']; $partner['signup_email'] = $partner_info['signup_email']; } $partner['partner_type'] = $partner_info['type']; $partner['org_type'] = $partner_info['org_type']; $partner['location_type'] = $partner_info['location_type']; $partner['facility_type'] = $partner_info['facility_type']; $partner['service_sites'] = $partner_info['service_sites']; $partner['ages_served'] = $partner_info['ages_served']; $partner['served_annually'] = $partner_info['served_annually']; $partner['staffing_totals'] = $partner_info['staffing_totals']; $partner['partner_status'] = $partner_info['status']; $partner['status'] = $partner_info['status']; $partner['quick_summary_a'] = $partner_info['quick_summary_a']; $partner['quick_summary_b'] = $partner_info['quick_summary_b']; $partner['quick_summary_c'] = $partner_info['quick_summary_c']; $partner['quick_summary_d'] = $partner_info['quick_summary_d']; $partner['quick_summary_e'] = $partner_info['quick_summary_e']; $partner['hold_date'] = $partner_info['hold_date']; $partner['partner_name'] = $partner_info['org_name']; $partner['org_name'] = $partner_info['org_name']; $partner['partner_addy1'] = $partner_info['address1']; $partner['partner_addy2'] = $partner_info['address2']; $partner['partner_city']= $partner_info['city']; $partner['partner_state'] = $partner_info['state']; $partner['partner_region'] = $partner_info['region']; $partner['partner_zip'] = $partner_info['zip']; $partner['partner_country'] = $partner_info['country']; //$partner['partner_email'] = $partner_info['email']; $partner['partner_url'] = $partner_info['url']; $partner['member_since'] = $partner_info['member_since']; $partner['member_since_month'] = $partner_info['member_since_month']; $partner['member_since_day'] = $partner_info['member_since_day']; $partner['member_since_year'] = $partner_info['member_since_year']; if ($partner_info['member_since_month'] && $partner_info['member_since_day'] && $partner_info['member_since_year']) { $partner['member_since_text'] = date("F jS, Y", mktime(0, 0, 0, $partner_info['member_since_month'], $partner_info['member_since_day'], $partner_info['member_since_year'])); } else if ($partner['member_since']) { $partner['member_since_year'] = substr($partner['member_since'], 0, 4); $partner['member_since_month'] = substr($partner['member_since'], 4, 2); $partner['member_since_day'] = substr($partner['member_since'], 6, 2); if ($partner['member_since_year'] && $partner['member_since_month'] && $partner['member_since_day']) { $partner['member_since_text'] = date("F jS, Y", mktime(0, 0, 0, $partner['member_since_month'], $partner['member_since_day'], $partner['member_since_year'])); } } $partner['priority'] = $partner_info['priority']; $partner['rating'] = $partner_info['rating']; $partner['mission'] = $partner_info['mission']; $partner['staff_full_time'] = $partner_info['staff_full_time']; $partner['staff_part_time'] = $partner_info['staff_part_time']; $partner['staff_voluntary'] = $partner_info['staff_voluntary']; $partner['training_support'] = $partner_info['training_support']; $partner['submit_date'] = $partner_info['submit_date']; $partner['last_updated'] = $partner_info['last_updated']; $partner['last_donation'] = $partner_info['last_donation']; $partner['staff_comment'] = $partner_info['staff_comment']; $partner['AoP_checked'] = $partner_info['AoP_checked']; $partner['501c3_checked'] = $partner_info['501c3_checked']; $partner['501c3_upload'] = $partner_info['501c3_upload']; $partner['501c3_desc'] = $partner_info['501c3_desc']; $partner['refurbisher'] = $partner_info['refurbisher']; $partner['recycler'] = $partner_info['recycler']; if ($db == "cristina_tmp") { $partner['site_origin'] = $partner_info['site_origin']; $partner['issued_partnerid'] = $partner_info['issued_partnerid']; $files_result = my_db_query("SELECT `501c3_upload` FROM `partner_info` WHERE (`id` = '" . mysql_escape_string($partnerid) . "')", "cristina_tmp"); if (mysql_numrows($files_result)) { $existing_result = mysql_fetch_assoc($files_result); $existing_files = explode("|",$existing_result['501c3_upload']); foreach ($existing_files as $fileid) { if ($lookup_list) $lookup_list .= ","; $lookup_list .= "'{$fileid}'"; } $filedata_result = my_db_query("SELECT * FROM `501c3_uploads` WHERE (`partnerid` = '" . mysql_escape_string($partnerid) . "') AND (`id` IN ({$lookup_list}))"); if (mysql_numrows($filedata_result)) { while ($filedata = mysql_fetch_assoc($filedata_result)) { $partner['501c3_files'][$filedata['id']] = $filedata['filename']; if ($file_list) $file_list .= "|"; $file_list .= "{$filedata['id']}"; } } $partner['501c3_upload'] = $file_list; my_db_query("UPDATE `partner_info` SET `501c3_upload` = '{$file_list}' WHERE (`id` = '" . mysql_escape_string($partnerid) . "')", "cristina_tmp"); } $partner['will_fax'] = $partner_info['will_fax']; } $partner['ref_num'] = $partner_info['ref_num']; $partner['tax_id'] = $partner_info['tax_id']; $partner['updated_when'] = $partner_info['updated_when']; $partner['updated_what'] = $partner_info['updated_what']; $partner['placement_contact'] = $partner_info['placement_contact']; $partner['lat'] = $location['lat']; $partner['lon'] = $location['lon']; // Get Award of Property agreement... $aop_terms_result = my_db_query("SELECT * FROM `aop_terms` WHERE (`partnerid` = '" . mysql_escape_string($partnerid) . "') ORDER BY `id` DESC LIMIT 1"); if (mysql_numrows($aop_terms_result)) { $aop_terms = mysql_fetch_assoc($aop_terms_result); } $partner['aop_terms'] = $aop_terms; // Get memberships for this partner... $memberships_result = my_db_query("SELECT `memberships`.*, `memberships_scopes`.`name` as `membership`, `memberships_scopes`.`desc` as 'membership_desc' FROM `memberships`, `memberships_scopes` WHERE (`memberships`.`scopeid` = `memberships_scopes`.`id`) AND (`memberships`.`member_table` = 'partner_info') AND (`memberships`.`member_id` = " . mysql_real_escape_string($partnerid) . ")"); if (mysql_numrows($memberships_result)) { while ($membership = mysql_fetch_assoc($memberships_result)) { $partner['memberships'][$membership['scopeid']] = $membership; } } // Get phpBB3 user accounts tied to this partner... if ($db == "cristina") { $phpbb_result = my_db_query("SELECT * FROM `partner_passport_link` WHERE (`partnerid` = {$partnerid})"); // Generate single WHERE statement to get name/email for users... while ($users = mysql_fetch_assoc($phpbb_result)) { if ($where) { $where .= " or "; } $where .= "(user_id = {$users['phpbb_user_id']})"; } // Get array of phpbb user information... if ($where) { $phpbb_result = my_db_query("SELECT `user_id`, `username`, `user_email` from `users` WHERE {$where}", "phpbb3"); if (mysql_numrows($phpbb_result)) { while ($phpbb_users = mysql_fetch_assoc($phpbb_result)) { $passports[strtolower($phpbb_users['user_email'])] = $phpbb_users['user_id']; $partner['passports'][$phpbb_users['user_id']] = $phpbb_users; } } } } if ($partner_info['phone_area'] && $partner_info['phone_prefix'] && $partner_info['phone_suffix']) { $partner['partner_phone_area'] = $partner_info['phone_area']; $partner['partner_phone_prefix'] = $partner_info['phone_prefix']; $partner['partner_phone_suffix'] = $partner_info['phone_suffix']; $partner['partner_phone_ext'] = $partner_info['phone_ext']; $partner['partner_phone'] = "({$partner_info['phone_area']}) {$partner_info['phone_prefix']}-{$partner_info['phone_suffix']}"; if ($partner_info['phone_ext'] != "") { $partner['partner_phone'] .= " x " . $partner_info['phone_ext']; } } if ($partner_info['fax_area'] && $partner_info['fax_prefix'] && $partner_info['fax_suffix']) { $partner['partner_fax_area'] = $partner_info['fax_area']; $partner['partner_fax_prefix'] = $partner_info['fax_prefix']; $partner['partner_fax_suffix'] = $partner_info['fax_suffix']; $partner['partner_fax'] = "({$partner_info['fax_area']}) {$partner_info['fax_prefix']}-{$partner_info['fax_suffix']}"; $partner['placement_fax'] = "({$partner_info['fax_area']}) {$partner_info['fax_prefix']}-{$partner_info['fax_suffix']}"; } // // grab all the contacts // $contact_result = my_db_query("SELECT * FROM `partner_contacts` WHERE partnerid = {$partner_info['id']}", $db); while ($contact_info = mysql_fetch_assoc($contact_result)) { $all_contacts[$contact_info['id']] = $contact_info; // Insert admin/director as top-level elements... if ($contact_info['contact_type'] == "admin" || $contact_info['contact_type'] == "director") { $partner['partner_contacts'][] = $contact_info['id']; $type_keys = array("{$contact_info['contact_type']}_name" => "name","{$contact_info['contact_type']}_title" => "title","{$contact_info['contact_type']}_phone_area" => "phone_area","{$contact_info['contact_type']}_phone_prefix" => "phone_prefix","{$contact_info['contact_type']}_phone_suffix" => "phone_suffix","{$contact_info['contact_type']}_phone_ext" => "phone_ext","{$contact_info['contact_type']}_fax_area" => "fax_area","{$contact_info['contact_type']}_fax_prefix" => "fax_prefix","{$contact_info['contact_type']}_fax_suffix" => "fax_suffix","{$contact_info['contact_type']}_email" => "email"); $contact_key = "partner_contact_" . $contact_info['id']; $partner[$contact_key]['contact_type'] = $contact_info['contact_type']; foreach($type_keys as $type_key => $key) { // This sets things like ['director_name'] and ['admin_phone_prefix'] in the main partner array... $partner[$type_key] = $contact_info[$key]; // This sets the contactid-specific ['partner_contact_contactid'] -> ['contact_name'] entries... $field_key = "contact_" . $key; $partner[$contact_key][$field_key] = $contact_info[$key]; } if ($passports[strtolower($contact_info['email'])]) { $partner[$contact_key]['contact_phpbb_user'] = $passports[strtolower($contact_info['email'])]; } $contactid_key = "{$contact_info['contact_type']}_contactid"; $partner[$contactid_key] = $contact_info['id']; if ($partner['director_phone_area'] && $partner['director_phone_prefix'] && $partner['director_phone_suffix']) { $partner['director_phone'] = "({$partner['director_phone_area']}) {$partner['director_phone_prefix']}-{$partner['director_phone_suffix']}"; if ($partner['director_phone_ext'] != "") { $partner['director_phone'] .= " x " . $partner['director_phone_ext']; } } if ($partner['director_fax_area'] && $partner['director_fax_prefix'] && $partner['director_fax_suffix']) { $partner['director_fax'] = "({$partner['director_fax_area']}) {$partner['director_fax_prefix']}-{$partner['director_fax_suffix']}"; if ($partner['director_fax_ext'] != "") { $partner['director_fax'] .= " x " . $partner['director_fax_ext']; } } if ($partner['admin_phone_area'] && $partner['admin_phone_prefix'] && $partner['admin_phone_suffix']) { $partner['admin_phone'] = "({$partner['admin_phone_area']}) {$partner['admin_phone_prefix']}-{$partner['admin_phone_suffix']}"; if ($partner['admin_phone_ext'] != "") { $partner['admin_phone'] .= " x " . $partner['admin_phone_ext']; } } if ($partner['admin_fax_area'] && $partner['admin_fax_prefix'] && $partner['admin_fax_suffix']) { $partner['admin_fax'] = "({$partner['admin_fax_area']}) {$partner['admin_fax_prefix']}-{$partner['admin_fax_suffix']}"; if ($partner['admin_fax_ext'] != "") { $partner['admin_fax'] .= " x " . $partner['admin_fax_ext']; } } // Other contacts... } else { $array_key = "partner_contact_" . $contact_info['id']; $partner['partner_contacts'][] = $contact_info['id']; $partner[$array_key]['contact_name'] = $contact_info['name']; $partner[$array_key]['contact_title'] = $contact_info['title']; $partner[$array_key]['contact_email'] = $contact_info['email']; $partner[$array_key]['contact_addy1'] = $contact_info['address_line1']; $partner[$array_key]['contact_addy2'] = $contact_info['address_line2']; $partner[$array_key]['contact_city'] = $contact_info['city']; $partner[$array_key]['contact_state'] = $contact_info['state']; $partner[$array_key]['contact_zip'] = $contact_info['zip']; $partner[$array_key]['contact_country'] = $contact_info['country']; $partner[$array_key]['contact_notes'] = $contact_info['staff_notes']; if ($passports[strtolower($contact_info['email'])]) { $partner[$array_key]['contact_phpbb_user'] = $passports[strtolower($contact_info['email'])]; } $partner[$array_key]['contact_phone_area'] = ""; $partner[$array_key]['contact_phone_prefix'] = ""; $partner[$array_key]['contact_phone_suffix'] = ""; $partner[$array_key]['contact_phone_ext'] = ""; if ($contact_info['phone_area'] && $contact_info['phone_prefix'] && $contact_info['phone_suffix']) { $partner[$array_key]['contact_phone_area'] = $contact_info['phone_area']; $partner[$array_key]['contact_phone_prefix'] = $contact_info['phone_prefix']; $partner[$array_key]['contact_phone_suffix'] = $contact_info['phone_suffix']; $partner[$array_key]['contact_phone_ext'] = $contact_info['phone_ext']; $partner[$array_key]['contact_phone'] = "({$contact_info['phone_area']}) {$contact_info['phone_prefix']}-{$contact_info['phone_suffix']}"; if ($contact_info['phone_ext'] != "") { $partner[$array_key]['contact_phone'] .= " x" . $contact_info['phone_ext']; } } if ($contact_info['fax_area'] && $contact_info['fax_prefix'] && $contact_info['fax_suffix']) { $partner[$array_key]['contact_fax_area'] = $contact_info['fax_area']; $partner[$array_key]['contact_fax_prefix'] = $contact_info['fax_prefix']; $partner[$array_key]['contact_fax_suffix'] = $contact_info['fax_suffix']; $partner[$array_key]['contact_fax_ext'] = $contact_info['fax_ext']; $partner[$array_key]['contact_fax'] = "({$contact_info['fax_area']}) {$contact_info['fax_prefix']}-{$contact_info['fax_suffix']}"; if ($contact_info['fax_ext'] != "") { $partner[$array_key]['contact_fax'] .= " x" . $contact_info['fax_ext']; } } $partner['extra_contacts'] .= " Name: " . $contact_info['name']; $partner['extra_contacts'] .= "\nTitle: " . $contact_info['title']; $partner['extra_contacts'] .= "\nPhone: " . $partner[$array_key]['contact_phone']; $partner['extra_contacts'] .= "\nEmail: " . $contact_info['email']; $partner['extra_contacts'] .= "\n[ ] Placement Contact\n\n"; } } if ($passports[strtolower($partner['admin_email'])]) { $partner['admin_phpbb_user'] = $passports[strtolower($partner['admin_email'])]; } if ($passports[strtolower($partner['director_email'])]) { $partner['director_phpbb_user'] = $passports[strtolower($partner['director_email'])]; } // Add in partner_project details... if (is_numeric($projectid)) { $project_search = "AND (id = {$projectid})"; $partner['projectid'] = $projectid; } $project_result = my_db_query("select * from `partner_project` where (partner_id = '{$partner_info['id']}') {$project_search} order by id asc", $db); $partner['project_details'] = array(); while ($project_info = mysql_fetch_assoc($project_result)) { $num_projects = array_push($partner['project_details'],$project_info); $partner['projectids'][] = $project_info['id']; // Get location info for this specific location... if ($locationid) { $lookuploc = " and (partner_locations.id = {$locationid})"; } //$locations_result = my_db_query("SELECT * FROM partner_locations WHERE (partnerid = {$partnerid}) AND ((projectid = {$project_info['id']}) || (`location_type` like 'main')){$lookuploc}"); //echo "\n\n"; $locations_result = my_db_query("SELECT partner_locations.* FROM partner_locations_link LEFT JOIN partner_locations ON partner_locations.id = partner_locations_link.locationid WHERE (partner_locations_link.partnerid = {$partnerid}) AND ((partner_locations_link.projectid = {$project_info['id']}) OR (partner_locations_link.projectid = '')) AND (`partner_locations`.`status` like 'active'){$lookuploc}", $db); while ($location = mysql_fetch_assoc($locations_result)) { $project_key = $num_projects - 1; if (($location['location_type'] == "main") || ($locationid == $location['id'])) { $partner['main_locationid'] = $location['id']; if ($location['lat'] && $location['lon']) { $partner['lat'] = $location['lat']; $partner['lon'] = $location['lon']; } $partner['address1'] = $location['address1']; $partner['address2'] = $location['address2']; $partner['city'] = $location['city']; $partner['state'] = $location['state']; $partner['region'] = $location['region']; $partner['zip'] = $location['zip']; $partner['country'] = $location['country']; $partner['email'] = $location['email']; $partner['partner_email'] = $location['email']; if ($location['url']) $partner['url'] = $location['url']; $partner['phone_area'] = $location['phone_area']; $partner['phone_prefix'] = $location['phone_prefix']; $partner['phone_suffix'] = $location['phone_suffix']; $partner['phone_ext'] = $location['phone_ext']; if ($location['phone_area'] && $location['phone_prefix'] && $location['phone_suffix']) { $partner['partner_phone'] = "({$location['phone_area']}) {$location['phone_prefix']}-{$location['phone_suffix']}"; if ($location['phone_ext']) $partner['partner_phone'] .= " x {$location['phone_ext']}"; } $partner['fax_area'] = $location['fax_area']; $partner['fax_prefix'] = $location['fax_prefix']; $partner['fax_suffix'] = $location['fax_suffix']; if ($location['fax_area'] && $location['fax_prefix'] && $location['fax_suffix']) { $partner['partner_fax'] = "({$location['fax_area']}) {$location['fax_prefix']}-{$location['fax_suffix']}"; if ($location['fax_ext']) $partner['partner_fax'] .= " x {$location['fax_ext']}"; } else { unset($partner['partner_fax'], $partner['partner_fax_area'], $partner['partner_fax_prefix'], $partner['partner_fax_suffix'], $partner['partner_fax_ext']); } } $partner['project_details'][$project_key]['locations'][$location['id']] = $location; } } // Determine which projectid to use... if ($partner['projectid']) { $lookupid = $partner['projectid']; } else { $lookupid = $partner['projectids'][0]; } // If locationid is specified, limit to that contact... if ($locationid) { $lookuploc = " and (locationid = {$locationid})"; } // Get placement contact for this partner/project/location... if (is_numeric($projectid) && $projectid) { $project_search = " AND (projectid = {$projectid})"; } else { $project_search = ""; } //echo "my_db_query(\"select * from placement_contacts where (partnerid = {$partner_info['id']}){$project_search}{$lookuploc}\");\n"; $placement_result = my_db_query("select * from `placement_contacts` where (partnerid = {$partner_info['id']}){$project_search}{$lookuploc}", $db); if (mysql_numrows($placement_result)) { // Because this loops through all placement contacts for this partner/project/location, it may // encounter more than one. In which case, it will store all but assign only the first it finds... while ($placement = mysql_fetch_assoc($placement_result)) { $placement_contact = $all_contacts[$placement['contactid']]; // Store found record... $partner['project_details'][array_search($placement['projectid'],$partner['projectids'])]['placement_contacts'][$placement['locationid']] = $placement_contact; $partner['project_details'][array_search($placement['projectid'],$partner['projectids'])]['placement_contacts'][$placement['locationid']]['phpbb_user'] = $placement['phpbb_user']; //echo "Storing
\n";
				//print_r($placement);
				//echo "
\n"; // Assign as placement contact... if (!$partner['placement_name']) { $partner['placement_name'] = $placement_contact['name']; $partner['placement_email'] = $placement_contact['email']; $partner['placement_title'] = $placement_contact['title']; $partner['placement_phpbb_user'] = $placement['phpbb_user']; if ($placement_contact['phone_area'] && $placement_contact['phone_prefix'] && $placement_contact['phone_suffix']) { $partner['placement_phone'] = "({$placement_contact['phone_area']}) {$placement_contact['phone_prefix']}-{$placement_contact['phone_suffix']}"; if ($placement_contact['phone_ext']) { $partner['placement_phone'] .= " x {$placement_contact['phone_ext']}"; } } $partner['placement_phone_area'] = $placement_contact['phone_area']; $partner['placement_phone_prefix'] = $placement_contact['phone_prefix']; $partner['placement_phone_suffix'] = $placement_contact['phone_suffix']; $partner['placement_phone_ext'] = $placement_contact['phone_ext']; } } // Partner application using the cristina_tmp db... } else if (($db == "cristina_tmp") && ($partner['project_details'][0]['placement_contact'])) { $placement_result = my_db_query("SELECT * FROM `partner_contacts` WHERE (`id` = {$partner['project_details'][0]['placement_contact']})", $db); if (mysql_numrows($placement_result)) { $placement_contact = mysql_fetch_assoc($placement_result); if ($placement_contact['name'] && $placement_contact['email']) { $partner['placement_name'] = $placement_contact['name']; $partner['placement_email'] = $placement_contact['email']; $partner['placement_phpbb_user'] = $placement['phpbb_user']; if ($placement_contact['phone_area'] && $placement_contact['phone_prefix'] && $placement_contact['phone_suffix']) { $partner['placement_phone'] = "({$placement_contact['phone_area']}) {$placement_contact['phone_prefix']}-{$placement_contact['phone_suffix']}"; if ($placement_contact['phone_ext']) { $partner['placement_phone'] .= " x {$placement_contact['phone_ext']}"; } } $partner['placement_phone_area'] = $placement_contact['phone_area']; $partner['placement_phone_prefix'] = $placement_contact['phone_prefix']; $partner['placement_phone_suffix'] = $placement_contact['phone_suffix']; $partner['placement_phone_ext'] = $placement_contact['phone_ext']; } } // Not stored in the new way, try the old... // This is necessary until we fully switch on the CN... } else { $partner['placement_contact'] = $partner_info['placement_contact']; if ($partner['placement_contact'] == "email") { $partner['placement_name'] = $partner['partner_name']; $partner['placement_email'] = $partner['partner_email']; $partner['placement_phone'] = $partner['partner_phone']; $partner['placement_phone_area'] = $partner['partner_phone_area']; $partner['placement_phone_prefix'] = $partner['partner_phone_prefix']; $partner['placement_phone_suffix'] = $partner['partner_phone_suffix']; $partner['placement_phone_ext'] = $partner['partner_phone_ext']; } elseif ($partner['placement_contact'] == "admin_email") { $partner['placement_name'] = $partner['admin_name']; $partner['placement_email'] = $partner['admin_email']; $partner['placement_phone'] = $partner['admin_phone']; $partner['placement_phone_area'] = $partner['admin_phone_area']; $partner['placement_phone_prefix'] = $partner['admin_phone_prefix']; $partner['placement_phone_suffix'] = $partner['admin_phone_suffix']; $partner['placement_phone_ext'] = $partner['admin_phone_ext']; } elseif ($partner['placement_contact'] == "director_email") { $partner['placement_name'] = $partner['director_name']; $partner['placement_email'] = $partner['director_email']; $partner['placement_phone'] = $partner['director_phone']; $partner['placement_phone_area'] = $partner['director_phone_area']; $partner['placement_phone_prefix'] = $partner['director_phone_prefix']; $partner['placement_phone_suffix'] = $partner['director_phone_suffix']; $partner['placement_phone_ext'] = $partner['director_phone_ext']; } elseif ($partner['placement_contact'] && (preg_match("/@/", $partner['placement_contact']))) { $contact_result = my_db_query("SELECT * FROM `partner_contacts` WHERE `email` = '" . mysql_escape_string($partner['placement_contact']) . "'", $db); $contact_num = mysql_numrows($contact_result); if ($contact_num > 0) { $contact_info = mysql_fetch_array($contact_result); $partner['placement_name'] = $contact_info['name']; if ($contact_info['phone_area'] && $contact_info['phone_prefix'] && $contact_info['phone_suffix']) { $partner['placement_phone_area'] = $contact_info['phone_area']; $partner['placement_phone_prefix'] = $contact_info['phone_prefix']; $partner['placement_phone_suffix'] = $contact_info['phone_suffix']; $partner['placement_phone_ext'] = $contact_info['phone_ext']; $partner['placement_phone'] = "({$contact_info['phone_area']}) {$contact_info['phone_prefix']}-{$contact_info['phone_suffix']}"; if ($contact_info['phone_ext'] != "") { $partner['placement_phone'] .= " x" . $contact_info['phone_ext']; } } } $partner['placement_email'] = $partner['placement_contact']; if ($partner['placement_phone'] == "") { $partner['placement_phone'] = $partner['partner_phone']; } } } // Build contact address info... $partner['partner_contact_text'] = " {$partner['org_name']}\n"; $partner['partner_contact_text'] .= " Attn: {$partner['placement_name']}\n"; $partner['partner_contact_text'] .= " {$partner['address1']}\n"; $partner['partner_contact_html'] = "{$partner['org_name']}
\n"; $partner['partner_contact_html'] .= "Attn: {$partner['placement_name']}
\n"; $partner['partner_contact_html'] .= "{$partner['address1']}
\n"; if ($partner['address2']) { $partner['partner_contact_text'] .= " {$partner['address2']}\n"; $partner['partner_contact_html'] .= "{$partner['address2']}
\n"; } $partner['partner_contact_text'] .= " {$partner['city']}, {$partner['state']} {$partner['zip']}\n"; $partner['partner_contact_html'] .= "{$partner['city']}, {$partner['state']} {$partner['zip']}
\n"; if ($partner['region']) { $partner['partner_contact_text'] .= " {$partner['region']}\n"; $partner['partner_contact_html'] .= "{$partner['region']}
\n"; } $partner['partner_contact_text'] .= " {$partner['country']}\n"; $partner['partner_contact_html'] .= "{$partner['country']}
\n"; $partner['partner_contact_text'] .= "\n Phone: {$partner['placement_phone']}\n"; $partner['partner_contact_html'] .= "
\n"; if ($partner['partner_fax']) { $partner['partner_contact_text'] .= " Fax: {$partner['partner_fax']}\n"; $partner['partner_contact_html'] .= "\n"; } if ($partner['placement_email']) { $partner['partner_contact_text'] .= " Email: {$partner['placement_email']}\n"; $partner['partner_contact_html'] .= "\n"; } $partner['partner_contact_html'] .= "
Phone: {$partner['placement_phone']}
Fax: {$partner['partner_fax']}
Email: {$partner['placement_email']}
\n"; // Build email signature... $partner['partner_signature_text'] .= "{$partner['placement_name']}\n"; $partner['partner_signature_text'] = "{$partner['org_name']}\n"; $partner['partner_signature_text'] .= "{$partner['address1']}\n"; $partner['partner_signature_html'] .= "{$partner['placement_name']}
\n"; $partner['partner_signature_html'] = "{$partner['org_name']}
\n"; $partner['partner_signature_html'] .= "{$partner['address1']}
\n"; if ($partner['address2']) { $partner['partner_signature_text'] .= "{$partner['address2']}\n"; $partner['partner_signature_html'] .= "{$partner['address2']}
\n"; } $partner['partner_signature_text'] .= "{$partner['city']}, {$partner['state']} {$partner['zip']}\n"; $partner['partner_signature_html'] .= "{$partner['city']}, {$partner['state']} {$partner['zip']}
\n"; if ($partner['region']) { $partner['partner_signature_text'] .= "{$partner['region']}\n"; $partner['partner_signature_html'] .= "{$partner['region']}
\n"; } // $partner['partner_signature_text'] .= "{$partner['country']}\n"; // $partner['partner_signature_html'] .= "{$partner['country']}
\n"; $partner['partner_signature_text'] .= "\nPhone: {$partner['placement_phone']}\n"; $partner['partner_signature_html'] .= "
\n"; if ($partner['partner_fax']) { $partner['partner_signature_text'] .= "Fax: {$partner['partner_fax']}\n"; $partner['partner_signature_html'] .= "\n"; } if ($partner['placement_email']) { $partner['partner_signature_text'] .= "Email: {$partner['placement_email']}\n"; $partner['partner_signature_html'] .= "\n"; } $partner['partner_signature_html'] .= "
Phone: {$partner['placement_phone']}
Fax: {$partner['partner_fax']}
Email: {$partner['placement_email']}
\n"; // Build general partner address info... $partner['partner_address_text'] .= " {$partner['address1']}\n"; $partner['partner_address_html'] .= "{$partner['address1']}
\n"; if ($partner['partner_address2']) { $partner['partner_address_text'] .= " {$partner['address2']}\n"; $partner['partner_address_html'] .= "{$partner['address2']}
\n"; } $partner['partner_address_text'] .= " {$partner['city']}, {$partner['state']} {$partner['zip']}\n"; $partner['partner_address_html'] .= "{$partner['city']}, {$partner['state']} {$partner['zip']}
\n"; if ($partner['region']) { $partner['partner_address_text'] .= " {$partner['region']}\n"; $partner['partner_address_html'] .= "{$partner['region']}
\n"; } $partner['partner_address_text'] .= " {$partner['country']}\n"; $partner['partner_address_html'] .= "{$partner['country']}
\n"; } // What memberships does this org hold? $memberships_result = my_db_query("SELECT `memberships`.`scopeid`, `memberships_scopes`.`name` AS `membership`, `memberships_scopes`.`desc`, `memberships`.`member_since` FROM `memberships_scopes`, `memberships` WHERE (`memberships`.`scopeid` = `memberships_scopes`.`id`) AND (`memberships`.`member_db` LIKE 'cristina') AND (`memberships`.`member_table` LIKE 'partner_info') AND (`memberships`.`member_id` = " . mysql_escape_string($partnerid) . ")"); if (mysql_numrows($memberships_result)) { while ($membership = mysql_fetch_assoc($memberships_result)) { $partner['memberships'][$membership['scopeid']] = $membership; } } // Which staff member typically deals with this US partner? $region_result = my_db_query("select user from regions where state = '{$partner['state']}'"); $region_num = mysql_numrows($region_result); if ($region_num > 0) { $user = mysql_fetch_assoc($region_result); $staff_result = my_db_query("select `name`, `extension` from `dtap_settings` where user = '{$user['user']}'"); $staff_num = mysql_numrows($staff_result); if ($staff_num > 0) { $staff = mysql_fetch_assoc($staff_result); $partner['staff_user'] = $user['user']; $partner['staff_name'] = $staff['name']; $partner['staff_ext'] = $staff['extension']; } // Must not be in the US... } else { // Default to Nancy for International partners... $partner['staff_user'] = "nancy"; $partner['staff_name'] = "Nancy Cortez"; $partner['staff_ext'] = "364"; } // echo "\n"; return $partner; } if (!function_exists('validate_email')) { function validate_email($email_address) { $email_addresses = split(",", $email_address); $valid = false; for ($i=0;$i"){ return false; } elseif (preg_match("/\.\./", $email_address)) { return false; } elseif(preg_match("/(^[\"\\a-zA-Z]{1,}(\s)?\<[+#\'a-zA-Z0-9_-]{1,}\@[a-zA-Z0-9-]{1,}\.[a-zA-Z0-9\.-]{1,}\>)/", $email_address)){ $valid = true; } elseif(preg_match("/(^[+#\'a-zA-Z0-9_-]{1,}\@[a-zA-Z0-9-]{1,}\.[a-zA-Z0-9\.-]{1,})/", $email_address)){ $valid = true; } elseif(preg_match("/^([*+!.&#$¦\'\\%\/0-9a-z^_`{}=?~:-]+)@(([0-9a-z-]+\.)+[0-9a-z]{2,4})$/i", trim($email_address))){ $valid = true; } else { return false; } } return $valid; }} function chunkFile($path, $table, $id, $delete = false) { global $error; if (file_exists($path)) { $fp = fopen($path, "rb"); //echo "\n"; // Start transaction... my_db_query("SET AUTOCOMMIT=0"); //echo "\n"; my_db_query("BEGIN"); //echo "\n"; $success = true; $i = 1; while(!feof($fp)) { // Read the data from the file 1MB at a time... //$data = fread($fp, 1048576); // 1MB (1024KB) chunks //$data = fread($fp, 524288); // .5MB (512KB) chunks $data = fread($fp, 262144); // .25MB (256KB) chunks //echo "\n"; $data = addslashes($data); $data = addcslashes($data, "\0"); // Do database insertion... if ($success == true) { $result = my_db_query("insert into binary_files (`table`,`referenceid`,`bin_data`, `part`) values ('{$table}','{$id}','{$data}','{$i}')","cristina",false); if (($result == false) && (mysql_affected_rows($GLOBALS['db_conn_write']) == 0)) { $success = false; //echo "\n"; } else { //echo "\n"; $i++; } } } fclose($fp); //echo "\n"; // Execute queries... if ($success == true) { my_db_query("COMMIT"); //echo "\n"; // Delete file now that it's imported into the database... if ($delete) { unlink($path); } return true; } } else { //echo $GLOBALS['error'] = "File not found at specified path ({$path})..."; return false; } } function getSize($bytes, $id) { if (!$bytes && $id) { // Load all the parts of this file in binary_data table... $size_result = my_db_query("select SUM(OCTET_LENGTH(bin_data)) as total_size from binary_files where referenceid = '{$id}'"); $size = mysql_fetch_assoc($size_result); $size = $size['total_size']; } else if ($bytes) { $size = $bytes; } $size = $size / 1024; if ($size < 1024) { $size = number_format($size, 2); $size .= ' KB'; } else { if ($size / 1024 < 1024) { $size = number_format($size / 1024, 2); $size .= ' MB'; } else if ($size / 1024 / 1024 < 1024) { $size = number_format($size / 1024 / 1024, 2); $size .= ' GB'; } } return $size; } function cached_include($key = "welcome", $revision = "") { // Make sure we're using the correct content/archive tables... if ($GLOBALS['content_table'] == "cgpn_content") { $content_table = "cgpn_content"; $archive_table = "cgpn_archive"; $cache_base = "/www/files/cgpn_cache"; } else { $content_table = "website_content"; $archive_table = "website_archive"; $cache_base = "/www/files/cache"; } if (trim($revision) != "" && is_numeric($revision)) { $revision_id = trim($revision); } elseif (trim($revision) != "") { error_out("Invalid Revision."); } if ($revision_id != "") { $filename = $cache_base . "/" . $key . "_" . $revision . ".inc"; $query = "SELECT `content`,`last_updated` FROM `{$archive_table}` WHERE (`key` = '" . mysql_escape_string($key) . "' AND id=$revision_id)"; } else { $filename = $cache_base . "/" . $key . ".inc"; $query = "SELECT `content`,`last_updated` FROM `{$content_table}` WHERE `key` = '" . mysql_escape_string($key) . "'"; } if (!is_dir($cache_base)) { if (!mkdir($cache_base, 0755)) { error_out("No write permissions to $cache_base."); } } if (preg_match("/proto/", $_SERVER['SERVER_NAME'])) { // proto dev mode $result = my_db_query($query, "cristina_tmp"); //echo "{$query}"; if (mysql_num_rows($result) > 0) { $content_info = mysql_fetch_array($result); if (!is_file($filename)) { // // create the file if it doesn't exist // $fh = fopen($filename, "w"); fwrite($fh, $content_info['content']); fclose($fh); } elseif ($content_info['last_updated'] > @filemtime($filename)) { // // update the file if we have new information // $fh = fopen($filename, "w"); fwrite($fh, $content_info['content']); fclose($fh); } } } else { // live mode // // only check for updates if the file is over 10 mins old... // if (!is_file($filename) || @filemtime($filename) < (time() - 600)) { $result = my_db_query($query); if (mysql_num_rows($result) > 0) { $update_info = mysql_fetch_assoc($result); if (!is_file($filename)) { // // create the file if it doesn't exist // $fh = fopen($filename, "w"); fwrite($fh, $update_info['content']); fclose($fh); } elseif ($update_info['last_updated'] > @filemtime($filename)) { // // update the file if we have new information // $fh = fopen($filename, "w"); fwrite($fh, $update_info['content']); fclose($fh); } else { // // touch it to reset the 10 minute timer // touch($filename); } } } } return $filename; } function template_cached_include($scope, $templateid, $pageid = "", $no_cache = false) { global $env; global $output; // Determine which db to use... //if (preg_match("/^proto/i", $_SERVER['HTTP_HOST']) || preg_match("/^dev/i", $_SERVER['HTTP_HOST']) || preg_match("/^es/i", $_SERVER['HTTP_HOST'])) { if (preg_match("/^proto/i", $_SERVER['HTTP_HOST']) || preg_match("/^dev/i", $_SERVER['HTTP_HOST'])) { $db = "cristina_tmp"; } else { $db = "cristina"; } //echo ""; // Set template tables based on scope/pageid... if ($scope == "cgpn") { $table_name = "cgpn_templates"; } else if ($scope == "npl") { $table_name = "npl_templates"; } else if ($scope == "dsf") { $table_name = "dsf_templates"; } else if ($scope == "needs") { $table_name = "partner_needs_templates"; } if ($pageid != "") { $page_table_name = str_replace("_templates","_page_templates",$table_name); } // Set where to store cached files... $cache_base = "/www/files/template_cache"; // Lookup master template information... $template_result = my_db_query("SELECT * FROM `{$table_name}` WHERE (`id` = " . mysql_escape_string($templateid) . ")", $db); if (mysql_numrows($template_result)) { $template = mysql_fetch_assoc($template_result); $GLOBALS[$template['name']] = $template; $update_info = $template; } else { error_out("Template ({$templateid}) Not Found in {$table_name}! Database: {$db}, Server: {$_SERVER['HTTP_HOST']}"); } if ($pageid != "") { $result = my_db_query("SELECT * FROM `{$page_table_name}` WHERE (`templateid` = {$templateid}) AND (`id` = " . mysql_escape_string($pageid) . ") limit 1", $db); if (mysql_numrows($result)) { $page_template = mysql_fetch_assoc($result); $filename = $cache_base . "/" . $template['name'] . "_" . $page_template['name'] . ".inc"; $GLOBALS[$template['name']][$page_template['name']] = $page_template; $replaced = str_replace("[PAGE_CONTENTS]",$page_template['template'],$template['template']); if ($replaced) { $update_info['template'] = $replaced; } else { $update_info = $page_template; } } else { error_out("Page Template ({$pageid}) Not Found!"); } } else { $filename = $cache_base . "/" . $template['name'] . ".inc"; } if (!is_dir($cache_base)) { if (!mkdir($cache_base, 0755)) { error_out("No write permissions to $cache_base."); } } // // only check for updates if the file is over 10 mins old... // if ($no_cache || !is_file($filename) || @filemtime($filename) < (time() - 600)) { if ($update_info['template'] != "") { // Strip any newlines and add slashes if displaying on external website... // This seems to get all mucked up on PHP5.3+!!! if ($env == "external") { //$update_info['template'] = preg_replace("/[\n\r]/","",str_replace("'","\'",$update_info['template'])); //$update_info['template'] = iconv("UTF-8", "ISO-8859-1//TRANSLIT", preg_replace("/[\n\r]/","",str_replace("'","\'",$update_info['template']))); //$update_info['template'] = iconv("UTF-8", "ISO-8859-1//TRANSLIT", preg_replace("/[\n\r]/","",str_replace("'","\'",$update_info['template']))); } if (!is_file($filename)) { // // create the file if it doesn't exist // $fh = fopen($filename, "w"); fwrite($fh, $update_info['template']); fclose($fh); } elseif (($update_info['last_modified'] > @filemtime($filename)) || $no_cache) { // // update the file if we have new information // $fh = fopen($filename, "w"); fwrite($fh, $update_info['template']); fclose($fh); } else { // // touch it to reset the 10 minute timer // touch($filename); } } } return $filename; } if (!function_exists("return_output")) { function return_output($file){ ob_start(); include $file; return ob_get_clean(); }} function page_meta($key) { // Make sure we're using the correct content/archive tables... if ($GLOBALS['content_table'] == "cgpn_content") { $content_table = "cgpn_content"; $archive_table = "cgpn_archive"; } else { $content_table = "website_content"; $archive_table = "website_archive"; } // // for normal page 404's // global $index_key, $key; // // for news 404's // global $news_resource, $article, $feedback, $blog; // // check for a news 404 // if ($key == "news" && $news_resource != "") { $data = split("[.-]", $news_resource); $id = $data[0]; if ($article != "") { $dept = "resource_article"; } elseif ($feedback != "") { $dept = "resource_feedback"; } elseif ($blog != "") { $dept = "resource_blog"; } if ($id != "" && $dept != "") { if ($GLOBALS['userdata']['username'] == "" || $GLOBALS['userdata']['username'] == "Anonymous") { $status = "(status = 'public')"; } else { $status = "(status = 'members' OR status = 'public')"; } $result = my_db_query("SELECT * FROM $dept WHERE (id='$id' AND {$status}) ORDER BY date_created LIMIT 5"); } if (mysql_num_rows($result) < 1) { $key = "404_error"; } } if (preg_match("/proto/i",$_SERVER['SERVER_NAME'])) { $db = "cristina_tmp"; $is_proto = true; } else { $db = "cristina"; $is_proto = false; } if ($key == "") { $search_key = "welcome"; } else { $search_key = $key; } //echo "my_db_query(\"SELECT `key`,id,parent_id,last_updated,title,description,keywords,subnav,subnav_title,bottom_nav,width FROM `{$content_table}` WHERE `key` = '" . mysql_escape_string($search_key) . "'\",$db);\n"; $result = my_db_query("SELECT `key`,id,parent_id,last_updated,title,description,keywords,subnav,subnav_title,bottom_nav,width FROM `{$content_table}` WHERE `key` = '" . mysql_escape_string($search_key) . "'",$db); if (mysql_num_rows($result) < 1 && $index_key) { $key = "404_error"; $search_key = $key; unset($result); $result = my_db_query("SELECT `key`,id,parent_id,last_updated,title,description,keywords,subnav,subnav_title,bottom_nav,width FROM `{$content_table}` WHERE `key` = '" . mysql_escape_string($search_key) . "'",$db); } if (mysql_num_rows($result) > 0) { // // assign the stuff from the db // $content_info = mysql_fetch_assoc($result); // // grab parent tidbits // $parent_result = my_db_query("SELECT `key`,parent_id FROM {$content_table} WHERE (`id` = '{$content_info['parent_id']}')",$db); if (mysql_num_rows($parent_result) > 0) { $parent = mysql_fetch_assoc($parent_result); $content_info['parent_key'] = $parent['key']; if ($parent['parent_id'] == 0) { $content_info['section'] = $parent['key']; } else { $this_parent = $parent['parent_id']; while ($this_parent != 0) { $result = my_db_query("SELECT id,parent_id,`key` FROM {$content_table} WHERE (id = '$this_parent')", $db); if (mysql_num_rows($result) > 0) { $this_meta_info = mysql_fetch_assoc($result); $this_parent = $this_meta_info['parent_id']; if ($this_parent == 0) { $content_info['section'] = $this_meta_info['key']; } } } } } // // and a couple more tidbits we've uncovered // $content_info['db'] = $db; $content_info['is_proto'] = $is_proto; // // and back to the action // return $content_info; } else { return false; } } function get_google_key() { global $_SERVER; // Determine which key to use based on the server... // echo "\n"; if ($_SERVER['SERVER_NAME'] == "proto.hpn.cristina.org") { $api_key = "ABQIAAAA_q_GBCCgg7eagpRrgylzmhSh-mGI40082lmrA5VnaCrFCnCbHRTrW-9Exv_5VMI65YnYEJHOV--hmg"; } else if ($_SERVER['SERVER_NAME'] == "proto.cristina.org") { $api_key = "ABQIAAAA_q_GBCCgg7eagpRrgylzmhRvLj0Eu0-q_eGOC-MaMagE6mEzDBSP7L64xBQ8kCy4OcXDEbnjqSaGiQ"; } else if ($_SERVER['SERVER_NAME'] == "proto.cvo.cristina.org") { $api_key = "ABQIAAAA_q_GBCCgg7eagpRrgylzmhQUqNVb7hL_bsxiEUKY3CjdVmib7RQ0rK4KtkLGmU8H_1MT1yaYlSxTlA"; } else if ($_SERVER['SERVER_NAME'] == "www.hpn.cristina.org") { $api_key = "ABQIAAAA_q_GBCCgg7eagpRrgylzmhStamRDPPNT1B6_blYsdCuH99iFSBQXbTPf8duwXHVL1Q-XPMzE2Qi80A"; } else { error_out("No google key available for host {$_SERVER['SERVER_NAME']}."); } return $api_key; } function content_map($parent_id=0, $db="cristina_tmp", $show_desc=true, $list_type="ul", $limit=false, $view_all = false) { global $meta_info; // Make sure we're using the right content table... if ($GLOBALS['content_table']) { $content_table = $GLOBALS['content_table']; } else { $content_table = "website_content"; } // // root level entries will have a parent id of zero // if ($preview) { $select = "`id`, `parent_id`, `priority`, `last_updated`, `key`, `title`, `description`, `subnav`, `subnav_title`, `width`, `content`"; } else { $select = "`id`, `parent_id`, `priority`, `last_updated`, `key`, `title`, `description`, `subnav`, `subnav_title`"; } $where = "WHERE 1"; if (!$view_all) { $view_limit = " AND (`sitemap` = 1)"; } if (!is_int($parent_id)) { $result_key_lookup = my_db_query("SELECT id FROM {$content_table} WHERE (`key`='{$parent_id}') $view_limit", $db); if (mysql_num_rows($result_key_lookup) > 0) { $key_info = mysql_fetch_assoc($result_key_lookup); $parent_id = $key_info['id']; } else { error_out("No such page, sorry."); } } if (!preg_match("/option/i",$list_type)) { $my_pages_result = my_db_query("SELECT {$select} FROM {$content_table} {$where} $view_limit ORDER BY parent_id, priority", $db); } else { $my_pages_result = my_db_query("SELECT {$select} FROM {$content_table} {$where} ORDER BY parent_id, priority", $db); } content_chunk(1, $my_pages_result, $parent_id, $show_desc, $list_type, $limit); return; } function content_chunk($depth, $result, $parent_id, $show_desc=true, $list_type="ul", $limit=false) { global $meta_info, $userdata; //echo "
\n";
	//print_r($meta_info);
	//echo "depth={$depth}\nparent_id={$parent_id}\nshow_desc={$show_desc}\nlist_type={$list_type}\nlimit={$limit}\n\n";
	
	if (preg_match("/ul/i",$list_type) || preg_match("/ol/i",$list_type)) {
		$li = "";
	}

	mysql_data_seek($result, 0);
	while ($my_page = mysql_fetch_assoc($result)) {
		if ($my_page['parent_id'] == $parent_id) {
			$display['id'][] = $my_page['id'];
			$display['parent_id'][] = $my_page['parent_id'];
			$display['key'][] = $my_page['key'];

			unset($title_append);
			if ($meta_info['is_proto']) {
				if (!page_is_live($my_page['key']) && $userdata['is_semi_admin']) {
					$title_append = " (publish live) ";
				}
			}
			$display['title'][] = $my_page['title'];
			$display['description'][] = $my_page['description'];
			//echo "\n";
		}
	}
	
	if ($limit && ($depth > 1) && (sizeof($display['title']) > $limit)) { $chunknum = $limit; } else { $chunknum = sizeof($display['title']); }

	//echo "display['title'] size=" . sizeof($display['title']) . "\nchunknum={$chunknum}\n
"; // Start the Management Guide sidebar navigation... if (preg_match("/guidenav/i",$list_type) && ($depth == 1)) { echo "\n \n \n \n"; } for ($i=0;$i<$chunknum;$i++) { $spacing = str_pad("", $depth*4, " "); unset($option_spacing); switch ($depth) { case 1: //if (preg_match("/ul/i",$list_type)) { $list_class = " class=\"ovalBullet\""; } $option_spacing = ""; $option_style = " style=\"background-color:#FFEAB9;\""; break; case 2: //if (preg_match("/ul/i",$list_type)) { $list_class = " class=\"normalBullet\""; } $option_spacing = "  » "; $option_style = " style=\"background-color:#FEF5DA;\""; break; case 3: //if (preg_match("/ul/i",$list_type)) { $list_class = " class=\"normalBullet\""; } $option_spacing = "       » "; $option_style = " style=\"background-color:#FFFAD9\""; break; case 4: //if (preg_match("/ul/i",$list_type)) { $list_class = " class=\"normalBullet\""; } $option_spacing = "           » "; $option_style = " style=\"background-color:#FFFFEC;\""; break; case 5: //if (preg_match("/ul/i",$list_type)) { $list_class = " class=\"normalBullet\""; } $option_spacing = "               » "; $option_style = " style=\"background-color:#FFFFFF;\""; break; } if (preg_match("/option/i",$list_type)) { $option_array = explode(":",$list_type); $value_type = $option_array[2]; if (!$value_type || ($value_type == "id")) { $selected_id = $option_array[1]; } else if ($value_type == "key") { $selected_key = $option_array[1]; } } // Main section entry... if ($parent_id == 0) { $this_class = "subHead"; // Start a new main-list... if (!$writeonce) { if (!preg_match("/option/i",$list_type) && !preg_match("/guidenav/i",$list_type)) { echo "<{$list_type}{$list_class}>\n"; $writeonce = true; } } // Subnav entry... } else { $this_class = "subnavLink"; // Start a new sub-list... if ($display['parent_id'][$i] != $last_parent_id) { if (!preg_match("/option/i",$list_type) && !preg_match("/guidenav/i",$list_type)) { echo "{$spacing}
\n"; echo "{$spacing}<{$list_type}{$list_class}>\n"; } } $last_parent_id = $display['parent_id'][$i]; } // Display the up/down and add subnav options... if ($GLOBALS['userdata']['session_logged_in'] && $GLOBALS['userdata']['allow_edit'] && !preg_match("/option/i",$list_type) && !preg_match("/guidenav/i",$list_type) && $GLOBALS['meta_info']['is_proto']) { // Disable the move up/down buttons if not a subnav entry... if (!$parent_id || (sizeof($display['title']) < 2)) { $move_disabled = " DISABLED"; } else { $move_disabled = ""; } echo "{$spacing}
{$li}\n"; echo "{$spacing}
\n"; echo "{$spacing}
\n"; echo "{$spacing}\n"; // Wrap site-map style ouptut in div... } else if (!preg_match("/option/i",$list_type) && !preg_match("/guidenav/i",$list_type)) { echo "{$spacing}
{$li}"; } // General site-map style output... if (!preg_match("/option/i",$list_type) && !preg_match("/guidenav/i",$list_type)) { echo "{$spacing}{$display['title'][$i]} " . $title_append; // Drop-down option output... } else if (preg_match("/option/i",$list_type)) { if ($selected_id == $display['id'][$i]) { $selected = " SELECTED"; } else { $selected = ""; } if ($selected_key == $display['key'][$i]) { $selected = " SELECTED"; } elseif (!$selected_id) { $selected = ""; } if (!$value_type || ($value_type == "id")) { echo "{$spacing}\n"; } else { echo "{$spacing}\n"; } // Management Guide sidebar nav... } else if (preg_match("/guidenav/i",$list_type)) { // Active main level section... if ((($meta_info['parent_id'] == $display['id'][$i]) || ($meta_info['id'] == $display['id'][$i])) && ($depth == 1)) { echo "
\n \n \n"; // Inactive main level section... } else if ($depth == 1) { echo " \n \n \n"; // Active sub section... } else if ($meta_info['id'] == $display['id'][$i]) { echo " \n \n \n"; // Inactive sub section... } else { echo " \n \n \n"; } } if ($show_desc && (!preg_match("/guidenav/i",$list_type))) { echo "
{$display['description'][$i]}
"; } // End list-item and div enclosure... if (!preg_match("/option/i",$list_type) && !preg_match("/guidenav/i",$list_type)) { echo "\n"; } if (!preg_match("/guidenav/i",$list_type) || (preg_match("/guidenav/i",$list_type) && (($meta_info['parent_id'] == $display['id'][$i]) || ($meta_info['id'] == $display['id'][$i])))) { content_chunk($depth+1, $result, $display['id'][$i], $show_desc, $list_type, $limit); } // End sub-list and div enclosures... if ($i == ($chunknum - 1)) { if (!preg_match("/option/i",$list_type) && !preg_match("/guidenav/i",$list_type)) { echo "{$spacing}\n"; echo "{$spacing}\n"; if ($limit && ($depth > 1) && ($limit < sizeof($display['title']))) { $allsubs = sizeof($display['title']); echo "+[show all {$allsubs}]\n"; } // Wrap up Management Guide navigation table... } else if (preg_match("/guidenav/i",$list_type) && ($depth == 1)) { echo "
Table of Contents
{$display['title'][$i]}
{$display['title'][$i]}
{$display['title'][$i]}
{$display['title'][$i]}
\n"; } } } unset($writeonce); return; } function send_file($file_name, $header_message = "") { $base_name = basename($file_name); $file_extension = strtolower(substr(strrchr($base_name,"."),1)); // Translate file name properly for Internet Explorer... if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE")){ $download_name = preg_replace('/\./', '%2e', $base_name, substr_count($base_name, '.') - 1); } else { $download_name = $base_name; } //This will set the Content-Type to the appropriate setting for the file switch ($file_extension) { case "htm": case "xhtml"; case "txt"; case "html": $content_type="text/html"; break; case "pdf": $content_type="application/pdf"; break; case "doc": $content_type="application/msword"; break; case "exe": $content_type="application/octet-stream"; break; case "zip": $content_type="application/zip"; break; case "xls": $content_type="application/vnd.ms-excel"; break; case "ppt": $content_type="application/vnd.ms-powerpoint"; break; case "gif": $content_type="image/gif"; break; case "png": $content_type="image/png"; break; case "jpeg": case "jpg": $content_type="image/jpeg"; break; case "mp3": $content_type="audio/mpeg"; break; case "wav": $content_type="audio/x-wav"; break; case "mpeg": case "mpg": case "mpe": $content_type="video/mpeg"; break; case "mov": $content_type="video/quicktime"; break; case "avi": $content_type="video/x-msvideo"; break; default: $content_type="application/force-download"; } if ($header_message != "") header("Custom-message: {$header_message}"); // Make sure the file exists before sending headers... if (!$fdl = @fopen($file_name,'r')) { error_out("Cannot Open File!"); } else { // Leave blank to avoid IE errors... header("Cache-Control: "); // Leave blank to avoid IE errors... header("Pragma: "); if ($content_type) { header("Content-type: {$content_type}"); } else { header("Content-type: application/octet-stream"); } // header("Content-Disposition: attachment; filename=\"" . $download_name . "\""); header("Content-length:" . (string)(filesize($file_name))); // // feof/echo fread is faster and easier on RAM // // fpassthru($fdl); // while(!feof($fdl)) { $buffer = fread($fdl, 2048); echo $buffer; } fclose($fdl); } return; } function clear_lock($key, $user = "", $force = false) { // Make sure we're using the correct content tables... if ($GLOBALS['content_table']) { $content_table = $GLOBALS['content_table']; } else { $content_table = "website_content"; } if ($key != "") { $result = my_db_query("SELECT locked,lock_id,lock_user,lock_epoch FROM {$content_table} WHERE `key` = '$key'", "cristina_tmp"); if (mysql_num_rows($result) > 0) { $lock_data = mysql_fetch_assoc($result); if ($lock_data['lock_user'] == $user || $force) { //remove lock $result = my_db_query("UPDATE {$content_table} SET locked = 0, lock_id = '', lock_user = '', lock_epoch = 0 WHERE `key` = '$key'", "cristina_tmp"); return true; } else { return false; } } else { return false; } } else { return false; } } // // $format = list|partial|full|rss // function list_news($how_many = 5, $section = "all", $format = "list", $category = "", $subcategory = "", $tags = "") { $sections_available = array("article", "blog", "feedback", "url"); if ($section == "all" && ($format != "rss" && $format != "atom")) { echo "
NONPROFIT NEWS & INFORMATION\"All
\n"; echo "
\n"; } if ($GLOBALS['userdata']['username'] == "" || $GLOBALS['userdata']['username'] == "Anonymous") { $where = "(r.status = 'public') AND "; } else { $where = "(r.status = 'members' OR r.status = 'public') AND "; } // // tags // allow comma separated values // if (preg_match("/,/", $tags)) { $tags_array = split(",", $tags); for ($i=0; $i < sizeof($tags_array); $i++) { if (trim($tags_array[$i]) != "") { if ($tag_string != "") $tag_string .= ", "; $tag_string .= "'" . trim(strtolower($tags_array[$i])) . "'"; } } if ($tag_string != "") { if ($extra_where != "") $extra_where .= " OR "; $extra_where = "(tm.tag_id = t.id AND r.id = tm.resource_id AND tm.resource_table = 'RESOURCE' AND t.tag IN (" . $tag_string . "))"; $extra_tables = ", resource_tags_map tm, resource_tags t"; } } elseif ($tags != "") { if ($extra_where != "") $extra_where .= " OR "; $extra_where .= "(tm.tag_id = t.id AND r.id = tm.resource_id AND tm.resource_table = 'RESOURCE' AND t.tag IN ('" . trim(strtolower($tags)) . "'))"; $extra_tables = ", resource_tags_map tm, resource_tags t"; } // // categories // allow comma separated values // if (preg_match("/,/", $category)) { $category_array = split(",", $category); for ($i=0; $i < sizeof($category_array); $i++) { if (is_numeric(trim($category_array[$i]))) { if ($extra_where != "") $extra_where .= " OR "; $extra_where .= "(r.category = " . trim($category_array[$i]) . ")"; } } } elseif (is_numeric($category) && $category != "") { if ($extra_where != "") $extra_where .= " OR "; $extra_where .= "(r.category = " . $category . ")"; } // // subcategories // allow comma separated values // if (preg_match("/,/", $subcategory)) { $subcategory_array = split(",", $subcategory); for ($i=0; $i < sizeof($subcategory_array); $i++) { if (is_numeric(trim($subcategory_array[$i]))) { if ($extra_where != "") $extra_where .= " OR "; $extra_where .= "(r.subcategory = " . trim($subcategory_array[$i]) . ")"; } } } elseif (is_numeric($subcategory) && $subcategory != "") { if ($extra_where != "") $extra_where .= " OR "; $extra_where .= "(r.subcategory = " . $subcategory . ")"; } if ($extra_where == "") { $full_where = "$where 1 "; } else { $full_where = "$where (" . $extra_where . ")"; } // // accomodate comma separated sections // and the "all" option // $section_array = split(",", $section); // // loop through the sections, determine what to pull out // for ($i = 0; $i < sizeof($sections_available); $i++) { $this_section = $sections_available[$i]; if (in_array($this_section, $section_array) || ($section == "all" && $extra_where == "")) { if ($SUB_SELECT != "") $SUB_SELECT .= " UNION "; $SUB_SELECT .= "(SELECT r.id,'" . $this_section . "' as source,r.title,r.date_live as go_date,r.creator,r.category,r.subcategory FROM resource_" . $this_section . " r WHERE $where 1 ORDER BY go_date DESC LIMIT $how_many)"; } elseif ($extra_where != "") { if (preg_match("/RESOURCE/", $extra_where)) { $full_where = "$where (" . str_replace("RESOURCE", "resource_" . $this_section, $extra_where) . ")"; } if ($SUB_SELECT != "") $SUB_SELECT .= " UNION "; $SUB_SELECT .= "(SELECT r.id,'" . $this_section . "' as source,r.title,r.date_live as go_date,r.creator,r.category,r.subcategory FROM resource_" . $this_section . " r $extra_tables WHERE $full_where ORDER BY go_date DESC LIMIT $how_many)"; } } // 02/08/08 // Getting a lot of broken queries where sub_select doesn't appear to be set... // Adding this if statement to see if it stops the errors... if ($SUB_SELECT) { $result = my_db_query($SUB_SELECT . " ORDER BY go_date DESC LIMIT $how_many"); } if (($format == "rss" || $format == "atom") && $DEBUG) { echo "" . $SUB_SELECT . " ORDER BY go_date DESC LIMIT $how_many\n"; } $i = 0; while ($resource = mysql_fetch_assoc($result)) { $resource['title'] = stripslashes(trim($resource['title'])); if (trim($resource['title']) == "") { if ($resource['source'] == "article") { $resource['title'] = "More Exciting News!"; } elseif ($resource['source'] == "feedback") { $resource['title'] = "More Exciting Feedback From The Field!"; } elseif ($resource['source'] == "blog") { $resource['title'] = "Another Exciting Blog From NCF!"; } elseif ($resource['source'] == "url") { $resource['title'] = "Another Exciting URL From NCF!"; } } if ($format == "list") { if (($i % 2) == 0) { $rowcolor = "#FFFFFF"; } else { $rowcolor = "#F2F2F2"; } if ($resource['source'] == "blog" || $resource['source'] == "article") { $img_icon = "\"News "; } else if ($resource['source'] == "feedback") { $img_icon = "\"Feedback "; } else { $img_icon = ""; } echo "
" . date("M j, Y", strtotime($resource['go_date'])) . "
\n"; echo "
{$img_icon}" . $resource['title'] . "
\n"; } elseif ($format == "partial") { get_news($resource['id'], "resource_" . $resource['source'], $format); } elseif ($format == "full") { get_news($resource['id'], "resource_" . $resource['source'], $format); } elseif ($format == "rss") { // // check category for xml_feed approval // $cat_xml_ok = false; if ($resource['category'] != 0) { $result_category = my_db_query("SELECT xml_feed FROM resource_categories WHERE id={$resource['category']}"); if (mysql_num_rows($result_category) > 0) { $category_info = mysql_fetch_assoc($result_category); $cat_xml_ok = $category_info['xml_feed']; } } else { $cat_xml_ok = true; } $subcat_xml_ok = false; if ($resource['subcategory'] != 0) { $result_subcategory = my_db_query("SELECT xml_feed FROM resource_subcategories WHERE id={$resource['subcategory']}"); if (mysql_num_rows($result_subcategory) > 0) { $subcategory_info = mysql_fetch_assoc($result_subcategory); $subcat_xml_ok = $subcategory_info['xml_feed']; } } else { $subcat_xml_ok = true; } if ($cat_xml_ok && $subcat_xml_ok) { get_news($resource['id'], "resource_" . $resource['source'], $format); } } elseif ($format == "atom") { // // check category for xml_feed approval // $cat_xml_ok = false; if ($resource['category'] != 0) { $result_category = my_db_query("SELECT xml_feed FROM resource_categories WHERE id={$resource['category']}"); if (mysql_num_rows($result_category) > 0) { $category_info = mysql_fetch_assoc($result_category); $cat_xml_ok = $category_info['xml_feed']; } } else { $cat_xml_ok = true; } $subcat_xml_ok = false; if ($resource['subcategory'] != 0) { $result_subcategory = my_db_query("SELECT xml_feed FROM resource_subcategories WHERE id={$resource['subcategory']}"); if (mysql_num_rows($result_subcategory) > 0) { $subcategory_info = mysql_fetch_assoc($result_subcategory); $subcat_xml_ok = $subcategory_info['xml_feed']; } } else { $subcat_xml_ok = true; } if ($cat_xml_ok && $subcat_xml_ok) { get_news($resource['id'], "resource_" . $resource['source'], $format); } } $i++; } if ($section == "all" && ($format != "rss" && $format != "atom")) echo "
\n"; } function get_news($id, $dept, $format = "full") { global $_SERVER; if ($format == "full") { $GLOBALS['log_this_page_resource_id'] = $id; $GLOBALS['log_this_page_resource_type'] = $dept; log_this_page("news"); } if ($format != "rss" && $format != "atom") echo "
\n"; if ($GLOBALS['userdata']['username'] == "" || $GLOBALS['userdata']['username'] == "Anonymous") { $status = "(status = 'public')"; } else { $status = "(status = 'members' OR status = 'public')"; } $result = my_db_query("SELECT * FROM $dept WHERE ((id='$id') and {$status}) ORDER BY date_live LIMIT 5"); while ($resource = mysql_fetch_assoc($result)) { $resource['title'] = stripslashes(trim($resource['title'])); if (trim($resource['title']) == "") { $permalink_tail = $resource['id'] . ".html"; } else { // for SEO $permalink_tail = $resource['id'] . "-" . htmlentities(urlencode($resource['title'])) . ".html"; } if (trim($resource['title']) == "") { if ($dept == "resource_article") { $resource['title'] = "Another Exciting Article From NCF!"; } elseif ($dept == "resource_feedback") { $resource['title'] = "More Exciting Feedback From The Field!"; } elseif ($dept == "resource_blog") { $resource['title'] = "Another Exciting Blog From NCF!"; } } if ($dept == "resource_article") { // Remove some funky characters making their way into the text... $resource['article_text'] = str_replace("â€","",$resource['article_text']); $resource['article_text'] = str_replace("Â","",$resource['article_text']); $resource['article_text'] = str_replace("â€","",$resource['article_text']); // zend studio doesn't like this for some reason // $resource['article_text'] = str_replace("?","",$resource['article_text']); if (preg_match("/
|
|

|<\/p>|<\/div>/i", $resource['article_text'])) { $type = "html"; } else { $type = "text"; } $result_category = my_db_query("SELECT category FROM resource_categories WHERE id={$resource['category']}"); if (mysql_num_rows($result_category) > 0) { $category_info = mysql_fetch_assoc($result_category); $category = $category_info['category']; } $result_subcategory = my_db_query("SELECT subcategory FROM resource_subcategories WHERE id={$resource['subcategory']}"); if (mysql_num_rows($result_subcategory) > 0) { $subcategory_info = mysql_fetch_assoc($result_subcategory); $subcategory = $subcategory_info['subcategory']; } if ($format == "partial") { $authdate = "Written: " . date("M j, Y", strtotime($resource['date_created'])) . " by " . stripslashes(trim($resource['author'])) . "\n"; echo "

" . $resource['title'] . "
\n"; echo "
{$authdate}
\n"; echo stripslashes(substr(strip_tags($resource['article_text']),0,300)) . "... read more\n

\n"; //echo "

Link to this page: http://www.cristina.org/article/" . $permalink_tail . "
Posted: " . $resource['date_created'] . " by " . trim($resource['author']) . "
\n"; } elseif ($format == "full") { echo "

{$resource['title']}

\n"; echo "
" . stripslashes($resource['article_text']) . "
\n"; $tags = explode(", ",$resource['tags']); foreach ($tags as $tag) { if ($display_tags) { $display_tags .= ", "; } $display_tags .= "{$tag}"; } echo "
Tags: {$display_tags}
\n"; if (trim($resource['url']) != "" && $type == "html") { $url_split = split("\/", $resource['url']); echo "

\"\" Digg | \"\" Technorati | \"\" Del.icio.us
"; if (!preg_match("/http:\/\/www.cristina.org\//i", $resource['url'])) echo "Read The Full Article (" . preg_replace("/^www./", "", $url_split[2]) . ")"; else echo " "; echo "

\n"; } elseif (trim($resource['url']) != "") { echo "\n\nRead the full article:\n{$resource['url']}\n\n"; } echo "
Link to this page: {$resource['title']}"; echo "
Originally Published: {$resource['date_published']} by {$resource['author']} at {$resource['publisher']}
\n"; } elseif ($format == "rss") { // Cleanup text for feed display... $description = preg_replace("/\"\/dbimages\//","\"http://www.cristina.org/dbimages/",stripslashes($resource['article_text'])); $description = preg_replace("/\"\/images\//","\"http://www.cristina.org/images/",stripslashes($description)); $description = preg_replace("/

\"\"

/","",$description); $description .= "

Originally Published: " . date("M j, Y", strtotime($resource['date_published'])) . " by " . trim(stripslashes($resource['author'])) . " at {$resource['publisher']}

\n"; $years = date("Y") - 1984; $description .= "

The National Cristina Foundation was founded by Yvette Marrin and David Bruce McMahan and for more than {$years} years has been Linking Life to its Promise.

\n"; if ($category != "") { $description .= " ($category"; if ($subcategory != "") { $description .= ":$subcategory"; } $description .=")\n"; } $description = preg_replace("/’|‘|“|”/", "'", $description); $description = str_replace("—", "-", $description); $description = str_replace(" ", " ", $description); echo " \n"; echo " " . trim(htmlentities($resource['title'])) . "\n"; echo " http://{$_SERVER["SERVER_NAME"]}/article/" . $permalink_tail . "\n"; echo " http://{$_SERVER["SERVER_NAME"]}/article/" . $permalink_tail . "\n"; echo " http://{$_SERVER["SERVER_NAME"]}/article/" . $permalink_tail . "#website_comments\n"; echo " \n"; echo " " . date("D, d M Y H:i:s T", strtotime($resource['date_live'])) . "\n"; echo " \n\n"; } elseif ($format == "atom") { // Cleanup text for feed display... $description = preg_replace("/\"\/dbimages\//","\"http://www.cristina.org/dbimages/",stripslashes($resource['article_text'])); $description = preg_replace("/\"\/images\//","\"http://www.cristina.org/images/",stripslashes($description)); $description = preg_replace("/

\"\"

/","",$description); $description .= "

Originally Published: " . date("M j, Y", strtotime($resource['date_published'])) . " by " . trim(stripslashes($resource['author'])) . " at {$resource['publisher']}

\n"; if ($category != "") { $description .= " ($category"; if ($subcategory != "") { $description .= ":$subcategory"; } $description .=")\n"; } $description = preg_replace("/’|‘|“|”/", "'", $description); $description = str_replace("—", "-", $description); $description = str_replace(" ", " ", $description); $years = date("Y") - 1984; $description .= "

The National Cristina Foundation was founded by Yvette Marrin and David Bruce McMahan and for more than {$years} years has been Linking Life to its Promise.

\n"; echo " \n"; echo " " . trim(htmlentities($resource['title'])) . "\n"; echo " http://{$_SERVER["SERVER_NAME"]}/article/" . $permalink_tail . "\n"; echo " http://{$_SERVER["SERVER_NAME"]}/article/" . $permalink_tail . "\n"; echo " \n"; echo " " . date("D, d M Y H:i:s T", strtotime($resource['date_live'])) . "\n"; echo " " . date("D, d M Y H:i:s T", strtotime($resource['date_created'])) . "\n"; echo " \n\n"; } } elseif ($dept == "resource_feedback") { if (preg_match("/
|
|

|<\/p>|<\/div>/i", $resource['feedback_text'])) { $type = "html"; } else { $type = "text"; } if ($format == "partial") { $authdate = "Provided: " . date("M j, Y", strtotime($resource['date_provided'])) . " by " . trim($resource['author']) . "\n"; echo "

" . $resource['title'] . "
\n"; echo "
{$authdate}
\n"; echo stripslashes(substr(strip_tags($resource['feedback_text']),0,300)) . "... read more\n

\n"; //echo "

" . $resource['title'] . "
\n"; //echo "
" . $resource['title'] . "
\n"; //echo "
\n"; //echo stripslashes($resource['feedback_text']); //echo "

 

\n"; /* echo "

\n"; echo "\n"; echo "Link to this page: http://www.cristina.org/feedback/" . $permalink_tail . "
\n"; echo "Written: " . date("M j, Y", strtotime($resource['date_provided'])) . " by " . trim($resource['author']) . "
\n"; echo "Posted: " . date("M j, Y", strtotime($resource['date_created'])) . " by " . ucwords(trim($resource['creator'])) . "\n"; echo "
\n"; */ } elseif ($format == "full") { //echo "
" . $resource['title'] . "
\n"; echo "\n"; echo "
" . $resource['title'] . "
\n"; echo "
\n"; // As this is feedback and will be nested within a dashedBox yellow container, // adjust any nested quote boxes so they have white backgrounds... $resource['feedback_text'] = str_replace('div class=\"spacedContent dashedBox\" style=\"padding','div class=\"spacedContent dashedBox\" style=\"background-color:#ffffff;padding',$resource['feedback_text']); echo stripslashes($resource['feedback_text']); echo "

 

\n"; /* echo "

\n"; echo "\n"; echo "Link to this page: http://www.cristina.org/feedback/" . $permalink_tail . "
\n"; echo "Written: " . date("M j, Y", strtotime($resource['date_provided'])) . " by " . trim($resource['author']) . "
\n"; echo "Posted: " . date("M j, Y", strtotime($resource['date_created'])) . " by " . ucwords(trim($resource['creator'])) . "\n"; echo "
\n"; */ } elseif ($format == "rss") { $description = stripslashes($resource['feedback_text']); $description .= "Written: " . date("M j, Y", strtotime($resource['date_provided'])) . " by " . trim($resource['author']) . "\n"; if ($category != "") { $description .= " ($category"; if ($subcategory != "") { $description .= ":$subcategory"; } $description .=")\n"; } $description = preg_replace("/‘|’|“|”/", "'", $description); $description = str_replace("—", "-", $description); $description = str_replace(" ", " ", $description); $description = str_replace(" & ", " and ", $description); echo " \n"; echo " " . trim(htmlentities($resource['title'])) . "\n"; echo " http://{$_SERVER["SERVER_NAME"]}/feedback/" . $permalink_tail . "\n"; echo " http://{$_SERVER["SERVER_NAME"]}/feedback/" . $permalink_tail . "\n"; echo " http://{$_SERVER["SERVER_NAME"]}/feedback/" . $permalink_tail . "#website_comments\n"; echo " \n"; echo " " . date("D, d M Y H:i:s T", strtotime($resource['date_live'])) . "\n"; echo " \n\n"; } elseif ($format == "atom") { $description = stripslashes($resource['feedback_text']); $description .= "Written: " . date("M j, Y", strtotime($resource['date_provided'])) . " by " . trim($resource['author']) . "\n"; if ($category != "") { $description .= " ($category"; if ($subcategory != "") { $description .= ":$subcategory"; } $description .=")\n"; } $description = preg_replace("/‘|’|“|”/", "'", $description); $description = str_replace("—", "-", $description); $description = str_replace(" ", " ", $description); $description = str_replace(" & ", " and ", $description); echo " \n"; echo " " . trim(htmlentities($resource['title'])) . "\n"; echo " http://{$_SERVER["SERVER_NAME"]}/feedback/" . $permalink_tail . "\n"; echo " http://{$_SERVER["SERVER_NAME"]}/feedback/" . $permalink_tail . "\n"; echo " \n"; echo " " . date("D, d M Y H:i:s T", strtotime($resource['date_live'])) . "\n"; echo " " . date("D, d M Y H:i:s T", strtotime($resource['date_created'])) . "\n"; echo " \n\n"; } } elseif ($dept == "resource_blog") { if (preg_match("/
|
|

|<\/p>|<\/div>/i", $resource['blog_text'])) { $type = "html"; } else { $type = "text"; } if ($format == "partial") { $authdate = "Written: " . date("M j, Y", strtotime($resource['date_created'])) . " by " . stripslashes(trim($resource['author'])) . "\n"; echo "

" . $resource['title'] . "
\n"; echo "
{$authdate}
\n"; echo stripslashes(substr(strip_tags($resource['blog_text']),0,300)) . "... read more\n

\n"; } elseif ($format == "full") { echo "

{$resource['title']}

\n"; echo "
" . stripslashes($resource['blog_text']) . "
\n"; if (trim($resource['url']) != "" && $type == "html") { $url_split = split("\/", $resource['url']); echo "

\"\" Digg | \"\" Technorati | \"\" Del.icio.us
Read The Full Blog (" . preg_replace("/^www./", "", $url_split[2]) . ")

\n"; } elseif (trim($resource['url']) != "") { echo "\n\nRead the full Blog:\n{$resource['url']}\n\n"; } echo "
Link to this page: {$resource['title']}"; echo "
Originally Published: {$resource['date_published']} by " . stripslashes($resource['author']) . " at {$resource['publisher']}
\n"; } elseif ($format == "rss") { $description = preg_replace("/\"\/images\/","\"http:\/\/www.cristina.org\/images\/",stripslashes($resource['blog_text'])); $description = preg_replace("/

\"\"

/","",$description); $description .= "

Originally Published: " . date("M j, Y", strtotime($resource['date_published'])) . " by " . trim(stripslashes($resource['author'])) . " at {$resource['publisher']}

\n"; $years = date("Y") - 1984; $description .= "

The National Cristina Foundation was founded by Yvette Marrin and David Bruce McMahan and for more than {$years} years has been Linking Life to its Promise.

\n"; //$description .= "Written: " . date("M j, Y", strtotime($resource['date_provided'])) . " by " . trim($resource['author']) . "\n"; if ($category != "") { $description .= " ($category"; if ($subcategory != "") { $description .= ":$subcategory"; } $description .=")\n"; } $description = preg_replace("/‘|’|“|”/", "'", $description); $description = str_replace("—", "-", $description); $description = str_replace(" ", " ", $description); echo " \n"; echo " " . trim(htmlentities($resource['title'])) . "\n"; echo " http://{$_SERVER["SERVER_NAME"]}/blog/" . $permalink_tail . "\n"; echo " http://{$_SERVER["SERVER_NAME"]}/blog/" . $permalink_tail . "\n"; echo " http://{$_SERVER["SERVER_NAME"]}/blog/" . $permalink_tail . "#website_comments\n"; echo " \n"; echo " " . date("D, d M Y H:i:s T", strtotime($resource['date_live'])) . "\n"; echo " \n\n"; } elseif ($format == "atom") { $description = preg_replace("/\"\/images\/","\"http:\/\/www.cristina.org\/images\/",stripslashes($resource['blog_text'])); $description = preg_replace("/

\"\"

/","",$description); $description .= "

Originally Published: " . date("M j, Y", strtotime($resource['date_published'])) . " by " . trim(stripslashes($resource['author'])) . " at {$resource['publisher']}

\n"; $years = date("Y") - 1984; $description .= "

The National Cristina Foundation was founded by Yvette Marrin and David Bruce McMahan and for more than {$years} years has been Linking Life to its Promise.

\n"; //$description .= "Written: " . date("M j, Y", strtotime($resource['date_provided'])) . " by " . trim($resource['author']) . "\n"; if ($category != "") { $description .= " ($category"; if ($subcategory != "") { $description .= ":$subcategory"; } $description .=")\n"; } $description = preg_replace("/‘|’|“|”/", "'", $description); $description = str_replace("—", "-", $description); $description = str_replace(" ", " ", $description); echo " \n"; echo " " . trim(htmlentities($resource['title'])) . "\n"; echo " http://{$_SERVER["SERVER_NAME"]}/blog/" . $permalink_tail . "\n"; echo " http://{$_SERVER["SERVER_NAME"]}/blog/" . $permalink_tail . "\n"; echo " \n"; echo " " . date("D, d M Y H:i:s T", strtotime($resource['date_live'])) . "\n"; echo " " . date("D, d M Y H:i:s T", strtotime($resource['date_created'])) . "\n"; echo " \n\n"; } } } if ($format != "rss" && $format != "atom") echo "
\n"; } if (!function_exists("get_comments")) { function get_comments($key) { global $_SERVER, $userdata, $comment_new, $comment_title, $comment_text; if ($comment_new) { if ($comment_title == "" || $comment_text == "") { echo "

Please include a complete title and comment when posting a new comment.

"; } elseif ($userdata['session_logged_in']) { if ($userdata['is_admin']) { $status = "public"; my_db_query("INSERT INTO resource_comment (`key`, status, title, creator, comment_text, date_created, reviewer, date_reviewed) VALUES ('$key', '$status', '" . mysql_escape_string($comment_title) . "', '" . $userdata['username'] . "', '" . mysql_escape_string($comment_text) . "', NOW(), '" . $userdata['username'] . "', NOW())"); } else { $status = "pending"; my_db_query("INSERT INTO resource_comment (`key`, status, title, creator, comment_text, date_created) VALUES ('$key', '$status', '" . mysql_escape_string($comment_title) . "', '" . $userdata['username'] . "', '" . mysql_escape_string($comment_text) . "', NOW())"); } echo "

Your comment has been entered!

"; } else { echo "

We're sorry, you must be logged in to submit a new comment.

"; } } echo "

 

\n
\n"; echo "\n"; echo "
Comments & Questions
\n"; $key_split = split("::", $key); $content_key = $key_split[0]; $sub_key = $key_split[1]; if ($userdata['session_logged_in']) { $result = my_db_query("SELECT * FROM resource_comment WHERE (`key`='$key' AND (status='members' OR status='public' OR creator='" . $userdata['username'] . "')) ORDER BY date_created DESC LIMIT 10"); } else { $result = my_db_query("SELECT * FROM resource_comment WHERE (`key`='$key' AND (status='public' OR creator='" . $userdata['username'] . "')) ORDER BY date_created DESC LIMIT 10"); } while ($comment = mysql_fetch_assoc($result)) { if ($comment['status'] != 'public' && $comment['status'] != 'members') { $status_blurb = " (pending approval)"; } else { $status_blurb = ""; } ?>
",htmlentities(stripslashes($comment['comment_text']))); ?>

" . htmlentities(stripslashes($comment['title'])) . $status_blurb . "
\n"; echo "
" . str_replace("\n", "
\n", htmlentities(stripslashes($comment['comment_text']))) . "
\n"; echo "
Posted: " . date("M j, Y", strtotime($comment['date_created'])) . " by " . trim($comment['creator']) . "
\n"; */ echo "

\n"; } if (mysql_num_rows($result) == 0) { echo "No Comments Found... Be the first to leave a comment!
\n"; } echo "


\n"; if ($userdata['session_logged_in']) { comment_form($key); } else { $prompt = "Want to leave a comment? Please log in!"; passport_form($prompt); } } function comment_form($this_key) { global $_SERVER; if ($_SERVER["HTTPS"] == "on") { $method = "https://"; } else { $method="http://"; } if ($_SERVER['QUERY_STRING'] != '') $_SERVER['QUERY_STRING'] = '?' . $_SERVER['QUERY_STRING']; $this_page = $method . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] . $_SERVER['QUERY_STRING']; ?>
Title:
Comment:
  


* All comments are subject to NCF review prior to publishing.

Log Out [" . $userdata['username'] . "]
\n

\n"; } else { ?>

Username:
Password:
[Register] [Recover Lost]   

\n"; $type_keys = array_keys($list_array); foreach ($type_keys as $key) { if (!is_int($key)) { $types[] = $key; //echo "\n"; foreach ($$key as $this_cat) { $this_subcat = $key . "_" . $this_cat; if (is_array($$this_subcat)) { //echo "\n"; } } } } //echo "\n"; ?>
Categories

Tags:

Add tags to your feed by entering them above. Just start typing and matching tags from our database will be displayed.

Tags will increase the resources returned by your feed subscription just like a search query.

You can use just tags, just categories, or both.

NOTE: Selecting "All Combined" categories will return every feed item possible. There's no reason to enter tags with this selection.

$type) { // Output a mainlevel resource type (e.g. Articles)... if (!is_array($list_array[$key])) { $class_name = "resource_type {$type}_type"; if ((sizeof($list_array) > 1) && ($t != sizeof($types))) { $col1_class = "midlineJunction"; } else if ($t == sizeof($types)) { $col1_class = "midlineTerminate"; } else { $col1_class = ""; } if (is_array($list_array[$type])) { if (sizeof($types) > 1) { $col2_class = "centerlineCorner"; } else { $col2_class = "centerlineTerminate"; } } else { $col2_class = "centerlineTerminate"; } // Spacer row... echo " \n"; echo " \n"; echo " \n"; if ($type == "url") { $display_type = strtoupper($type); } else { $display_type = ucwords($type); } echo " \n"; echo " \n"; echo " \n"; if ($type == "url") { echo " \n"; } else { echo " \n"; } echo " \n"; $t++; // Display the categories within this resource type... } else { // Walk through all categories... $c = 1; foreach ($list_array[$key] as $catkey => $catvalue) { // Output midlevel category... if (!is_array($list_array[$key][$catkey])) { if ((sizeof($list_array) > 1) && (($t - 1) != sizeof($types))) { $col1_class = "midlineRun"; } else { $col1_class = ""; } if ((sizeof($list_array[$key]) > 1) && ($c != sizeof(${$key}))) { $col2_class = "midlineJunction"; } else { $col2_class = "midlineTerminate"; } $this_subcat = $key . "_" . $catvalue; if ((sizeof($$this_subcat) > 1)) { $col3_class = "centerlineCorner"; } else if (!is_array(${$this_subcat})) { $col3_class = "centerlineTerminate"; } else if ($c == sizeof(${$key})) { $col3_class = "centerlineTerminate"; } else { $col3_class = ""; } $class_name = $key . "_" . strtolower(str_replace(" ","_",$catvalue)); $descid = "{$key}_{$catkey}"; if ($descriptions[$descid] != "") { if ($key == "url") { $display_type = strtoupper($key); } else { $display_type = ucwords($key); } $title = " title=\"header=[{$display_type} Feed] body=[" . stripslashes(htmlentities($descriptions[$descid], ENT_QUOTES)) . "] delay=[500]\""; } else { $title = ""; } echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; $c++; // Output all subcategories for this category... } else { $s = 1; foreach ($list_array[$key][$catkey] as $subkey => $subvalue) { $this_subcat = $key . "_" . $catkey; if ((sizeof($list_array) > 1) && ($t <= sizeof($types))) { $col1_class = "midlineRun"; } else { $col1_class = ""; } if ((sizeof($list_array[$key]) > 1) && ($c <= sizeof(${$key}))) { $col2_class = "midlineRun"; } else { $col2_class = ""; } if ($s < (sizeof(${$this_subcat}))) { $col3_class = "midlineJunction"; } else if ($s == (sizeof(${$this_subcat}))) { $col3_class = "midlineTerminate"; } else { $col3_class = ""; } $class_name = $key . "_" . strtolower(str_replace(" ","_",$catkey)) . "_subcategory"; $this_catid = array_keys($list_array[$key], $catkey); $descid = "{$key}_{$this_catid[0]}_{$subkey}"; if ($descriptions[$descid] != "") { if ($key == "url") { $display_type = strtoupper($key); } else { $display_type = ucwords($key); } $title = " title=\"header=[{$display_type} Feed] body=[" . stripslashes(htmlentities($descriptions[$descid], ENT_QUOTES)) . "] delay=[500]\""; } else { $title = ""; } echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; $s++; } } } } } ?>
 All Combined
  " . strtoupper($type) . "s (Websites) " . ucwords($type) . "s
   " . $catvalue . "
    " . $subvalue . "

Publish Live
"; return false; } else { $live_info = mysql_fetch_assoc($result_live); $result_proto = my_db_query("SELECT * FROM {$content_table} WHERE `key` = '" . $key . "'", "cristina_tmp"); $proto_info = mysql_fetch_assoc($result_proto); if ($live_info['content'] != $proto_info['content']) { if (!$quiet) echo "This page's content differs from the live site. Publish Live"; return false; } elseif ($live_info['title'] != $proto_info['title']) { if (!$quiet) echo "This page's title differs from the live site. Publish Live"; return false; } elseif (($live_info['priority'] != $proto_info['priority']) || ($live_info['keywords'] != $proto_info['keywords']) || ($live_info['subnav'] != $proto_info['subnav']) || ($live_info['subnav_title'] != $proto_info['subnav_title']) || ($live_info['sitemap'] != $proto_info['sitemap']) || ($live_info['width'] != $proto_info['width']) || ($live_info['bottom_nav'] != $proto_info['bottom_nav'])) { if (!$quiet) echo "This page's settings differ from the live site. Publish Live"; return false; } } return true; } function log_this_page($scope = "") { global $_SERVER, $_GET, $_POST, $session_login, $donorid, $sessionid, $partnerid, $resource; // // gather info // $browser = mysql_escape_string($_SERVER["HTTP_USER_AGENT"]); $request_uri = mysql_escape_string($_SERVER["REQUEST_URI"]); $remote_ip = $_SERVER["REMOTE_ADDR"]; $local_ip = $_SERVER["SERVER_ADDR"]; $server_name = $_SERVER["SERVER_NAME"]; $method = $_SERVER["REQUEST_METHOD"]; // Make sure all INT fields are entered properly... $int_fields = array("donorid","partnerid","resource_id"); foreach($int_fields as $field) { if ($$field && (!is_numeric($$field))) { $set_field = "this_" . $field; $$set_field = 404; } else { $set_field = "this_" . $field; $$set_field = $$field; } } if ($this_donorid == "") { $this_donorid = 0; } if ($this_partnerid == "") { $this_partnerid = 0; } if ($GLOBALS['log_this_page_resource_id'] == "") { $GLOBALS['log_this_page_resource_id'] = 0; } $GLOBALS['log_this_page_resource_type'] = preg_replace("/^resource_/", "", $GLOBALS['log_this_page_resource_type']); $get_vars = mysql_escape_string(print_r($_GET, TRUE)); $post_vars = mysql_escape_string(print_r($_POST, TRUE)); $table_name = date("Y-M") . "_access_logs"; my_db_query("INSERT INTO `$table_name` (`scope`, `remote_ip`, `server_ip`, `server_name`, `request_uri`, `donorid`, `sessionid`, `partnerid`, `resource_type`, `resource_id`, `browser`, `session_login`, `method`, `get_vars`, `post_vars`) VALUES ('$scope', '$remote_ip', '$local_ip', '$server_name', '$request_uri', $this_donorid, '$sessionid', $this_partnerid, '{$GLOBALS['log_this_page_resource_type']}', {$GLOBALS['log_this_page_resource_id']}, '$browser', '$session_login', '$method', '$get_vars', '$post_vars')", "cristina_logging"); } function var_training($post_only_vars,$post_or_get_vars) { // // training... this should help us recognize new post values // $post_vars = array_keys($_POST); for ($i = 0;$i < sizeof($post_vars);$i++) { if (!is_array($post_only_vars) || !in_array($post_vars[$i], $post_only_vars)) { $post_only_vars[] = $post_vars[$i]; } my_db_query("INSERT INTO website_variables (varname, method, initial_request_uri) VALUES ('{$post_vars[$i]}', 'POST', '" . mysql_escape_string($_SERVER['REQUEST_URI']) . "') ON DUPLICATE KEY UPDATE last_request_uri='" . mysql_escape_string($_SERVER['REQUEST_URI']) . "'"); } // // training... this should help us recognize new get values // $get_vars = array_keys($_GET); for ($i = 0;$i < sizeof($get_vars);$i++) { if (!is_array($post_or_get_vars) || !in_array($get_vars[$i], $post_or_get_vars)) { $post_or_get_vars[] = $get_vars[$i]; } my_db_query("INSERT INTO website_variables (varname, method, initial_request_uri) VALUES ('{$get_vars[$i]}', 'GET', '" . mysql_escape_string($_SERVER['REQUEST_URI']) . "') ON DUPLICATE KEY UPDATE last_request_uri='" . mysql_escape_string($_SERVER['REQUEST_URI']) . "'"); } } function get_generations($table, $showgens = array('1','2','3','4'), $offset = 0, $scope = "dsf", $hidden = 0, $consolidated = true, $return = "display") { // // $hidden [0/1] allows you to choose between hidden and non-hidden objects // $consolidated [0/1] allows you to alter the display to consolidate the options when displaying them // // Quick little function to add the offset... if (!function_exists('add_offset')) { function add_offset(&$val,$key,$offset) { $val = $val + $offset; } } // $showgens isn't in array format... if (!is_array($showgens)) { // Range Format: 1-3 if (preg_match("/-/",$showgens)) { $gens = explode("-",trim($showgens)); $firstgen = $gens[0]; $lastgen = $gens[1]; if (is_numeric($firstgen) && is_numeric($lastgen) && ($firstgen <= $lastgen)) { for ($i = $firstgen;$i <= $lastgen;$i++) { $generations[] = $i; } } else { echo "Error: generations ({$showgens}) not in proper format (for exmaple: 1-4)\n"; exit; } // Delimited Format: 1,3,4 } else if (preg_match("/,/",$showgens)) { $generations = explode(",",$showgens); // Singular Format: 3 } else if (is_numeric($showgens)) { $generations = array($showgens); } else if ($showgens == "all") { // Get max generation possible... $max_result = my_db_query("select MAX(generation) as max_gen from form_options"); $max_gen = mysql_result($max_result,0,"max_gen"); for ($i = 0;$i <= $max_gen;$i++) { $generations[] = $i; } } else if ($showgens == "active") { // // Get all active generations // unset($where_fields); $form_result = my_db_query("SELECT field_name, field_title_text FROM form_fields WHERE (table_name='$table' AND is_generational=1) ORDER BY display_order asc"); while ($fields = mysql_fetch_assoc($form_result)) { if ($where_fields != "") $where_fields .= " OR "; $where_fields .= "field_name='" . $fields['field_name'] . "'"; } if ($where_fields != "") { $max_result = my_db_query("select MAX(generation) as max_gen, MIN(generation) as min_gen from form_options WHERE (($where_fields) AND table_name='$table' AND generation != 0 AND hidden=0)"); $max_gen = mysql_result($max_result,0,"max_gen"); $min_gen = mysql_result($max_result,0,"min_gen"); for ($i = $min_gen;$i <= $max_gen;$i++) { $generations[] = $i; } } else { // echo "
Warning: This item type has no generational options associated with it.
"; } } else { echo "Error: generations ({$showgens}) in unknown format, please use one of the following: [1-4], [1,3,4], [3], [array(\"1\",\"3\",\"4\")]\n"; exit; } } else { $generations = $showgens; } $master_array['gen_min'] = 1000; // something really high, it comes DOWN from here. $master_array['gen_max'] = 0; // something really low, it goes UP from here. // // Get list of item fields for generational display... // $is_numeric = false; if (is_array($generations)) { // Add any specified offset... array_walk($generations,"add_offset",$offset); // // loop through each gen selected // foreach ($generations as $gen) { unset($prev_option,$is_numeric); // // handle the min/max settings // if ($gen < $master_array['gen_min']) $master_array['gen_min'] = $gen; if ($gen > $master_array['gen_max']) $master_array['gen_max'] = $gen; $display_gen = $gen - $offset; $display_array[$display_gen] = array(); $form_result = my_db_query("SELECT field_name, field_title_text, is_generational FROM form_fields WHERE (table_name='$table' AND (is_generational=1 or is_generational=2)) ORDER BY display_order asc"); while ($fields = mysql_fetch_assoc($form_result)) { $master_array['is_generational'][$fields['field_name']] = $fields['is_generational']; $master_array['is_generational'][$fields['field_title_text']] = $fields['is_generational']; $master_array['text2table'][$fields['field_title_text']] = $fields['field_name']; $master_array['table2text'][$fields['field_name']] = $fields['field_title_text']; unset($prev_option,$is_numeric); if ($consolidated) { // Grouped option, get em all... if ($fields['is_generational'] == 2) { $generational_result = my_db_query("SELECT DISTINCT option_text FROM form_options WHERE (table_name='$table' AND field_name='{$fields['field_name']}' AND hidden=$hidden) ORDER BY field_name, sort_order"); $debug .= "Searching for grouped field {$fields['field_name']} options (consolidated)...\n"; // Strctly a generational field, get this gen and higher... } else { $generational_result = my_db_query("SELECT DISTINCT option_text FROM form_options WHERE (table_name='$table' AND field_name='{$fields['field_name']}' AND generation>=$gen AND hidden=$hidden) ORDER BY field_name, sort_order"); $debug .= "Searching for field {$fields['field_name']} options (consolidated)...\n"; } } else { $generational_result = my_db_query("SELECT DISTINCT option_text FROM form_options WHERE (table_name='$table' AND field_name='{$fields['field_name']}' AND generation=$gen AND hidden=$hidden) ORDER BY field_name, sort_order"); $debug .= "Searching for field {$fields['field_name']} options (generation specific)...\n"; } while ($options = mysql_fetch_assoc($generational_result)) { // Add to master array... if (is_array($master_array[$display_gen][$fields['field_title_text']])) { array_push($master_array[$display_gen][$fields['field_title_text']],$options['option_text']); } else { $master_array[$display_gen][$fields['field_title_text']] = array_values($options); } // // try to detect numbers showing up all in a row // if (preg_match("/^([0-9]{1,20})/", $options['option_text'])) { if (!$is_numeric) { $is_numeric = true; if ($display_array[$display_gen][$fields['field_title_text']]) { $display_array[$display_gen][$fields['field_title_text']] .= ", "; $action = "Adding to"; } else { $action = "Setting"; } $display_array[$display_gen][$fields['field_title_text']] .= $options['option_text']; $debug .= "{$action} {$fields['field_title_text']} = {$options['option_text']}\n"; } else { $prev_option = $options['option_text']; $debug .= "Storing previous as {$options['option_text']}\n"; } } else { if (!$is_numeric) { unset($prev_option); if ($display_array[$display_gen][$fields['field_title_text']]) { $display_array[$display_gen][$fields['field_title_text']] .= ", "; } $display_array[$display_gen][$fields['field_title_text']] .= $options['option_text']; $debug .= "Adding to {$fields['field_title_text']} = {$options['option_text']}\n"; } else { $is_numeric = false; if ($prev_option) { if ($consolidated) { $display_array[$display_gen][$fields['field_title_text']] .= " - {$prev_option}"; } $action = "Finishing range of {$fields['field_title_text']} with {$prev_option} and adding {$options['option_text']}"; } else { $action = "Adding to {$fields['field_title_text']} = {$options['option_text']}"; } if ($display_array[$display_gen][$fields['field_title_text']]) { $display_array[$display_gen][$fields['field_title_text']] .= ", "; } $display_array[$display_gen][$fields['field_title_text']] .= $options['option_text']; $debug .= "{$action}\n"; } } } if ($is_numeric && $prev_option) { $is_numeric = false; if ($consolidated) { $display_array[$display_gen][$fields['field_title_text']] .= " - {$prev_option}"; } $debug .= "Finishing range of {$fields['field_title_text']} with {$prev_option}\n"; } } } } else { $master_array['gen_min'] = 0; $master_array['gen_max'] = 0; } /* echo "
\n";
	echo "\n[Display Array]\n";
	print_r($display_array);
	echo "\n[Master Array]\n";
	print_r($master_array);
	echo "
\n"; echo "
\n";
	echo "\n[Debug Info]\n";
	echo $debug;
	echo "
\n"; */ if ($return == "display") { return $display_array; } else if ($reutrn = "master") { return $master_array; } } function donor_passport_link($donorid = 0, $email = "") { global $userdata; if ($userdata['user_id'] != 0 && $userdata['user_id'] != -1) { if ($donorid != 0 && $email != "") { $result = my_db_query("SELECT donorid FROM donor_info WHERE (donorid = $donorid AND email LIKE '$email')"); if (mysql_num_rows($result) > 0) { my_db_query("DELETE FROM donor_passport_link WHERE (phpbb_user_id = {$userdata['user_id']} AND donorid = {$donorid})"); my_db_query("INSERT INTO donor_passport_link (phpbb_user_id, donorid) VALUES ({$userdata['user_id']}, {$donorid})"); //echo "\n"; } } $result = my_db_query("SELECT donorid FROM donor_info WHERE (email LIKE '" . $userdata['user_email'] . "')"); while ($donor_info = mysql_fetch_assoc($result)) { my_db_query("DELETE FROM donor_passport_link WHERE (phpbb_user_id = {$userdata['user_id']} AND donorid = {$donor_info['donorid']})"); my_db_query("INSERT INTO donor_passport_link (phpbb_user_id, donorid) VALUES ({$userdata['user_id']}, {$donor_info['donorid']})"); //echo "\n"; } } } function partner_passport_link($partnerid = 0, $email = "") { global $userdata; $group_add = false; //echo "\n"; if ($userdata['user_id'] != 0 && $userdata['user_id'] != -1) { if ($partnerid != 0 && trim($email) != "") { $result = my_db_query("SELECT id FROM partner_info WHERE ($id = $partnerid AND (email LIKE '$email' OR admin_email LIKE '$email' OR director_email LIKE '$email')) and (status like 'active')"); if (mysql_num_rows($result) > 0) { // my_db_query("DELETE FROM partner_passport_link WHERE (phpbb_user_id = {$userdata['user_id']} AND partnerid = {$partnerid})"); my_db_query("INSERT IGNORE INTO partner_passport_link (phpbb_user_id, partnerid) VALUES ({$userdata['user_id']}, {$partnerid})"); if (!$group_add) { my_db_query("USE phpbb3"); group_user_add(9, array($userdata['user_id'])); $group_add = true; my_db_query("USE cristina"); } //echo "\n"; } } if (trim($userdata['user_email']) != "") { unset($partner_info); $result = my_db_query("SELECT partnerid FROM partner_contacts WHERE (email LIKE '" . $userdata['user_email'] . "')"); while ($partner_info = mysql_fetch_assoc($result)) { // my_db_query("DELETE FROM partner_passport_link WHERE (phpbb_user_id = {$userdata['user_id']} AND partnerid = {$partner_info['partnerid']})"); my_db_query("INSERT IGNORE INTO partner_passport_link (phpbb_user_id, partnerid) VALUES ({$userdata['user_id']}, {$partner_info['partnerid']})"); if (!$group_add) { my_db_query("USE phpbb3"); group_user_add(9, array($userdata['user_id'])); $group_add = true; my_db_query("USE cristina"); } //echo "\n"; } } } } function donation_history($partnerid, $sessionid, $donorid, $format = "table_summary", $db = "cristina") { $donor_result = my_db_query("SELECT * FROM donor_info WHERE donorid = $donorid", $db); if (mysql_num_rows($donor_result) > 0) { $donor_info = mysql_fetch_assoc($donor_result); } else { error_out("No such donor Donor ID: $donorid"); } // // not sure we need this? // ... but wrote it anyway... // // $partner_result = my_db_query("SELECT * FROM partner_info WHERE id = $partnerid"); // if (mysql_num_rows($partner_result) > 0) { // $partner_info = mysql_fetch_assoc($partner_result); // } else { // error_out("No such partner Partner ID: $partnerid"); // } if ($partnerid != "") { $partner_where = " AND (partnerid = '$partnerid' OR partnerid REGEXP '^$partnerid:' OR partnerid REGEXP ':$partnerid:')"; } $session_result = my_db_query("SELECT * FROM donation_summary WHERE (donorid = $donorid AND sessionid = '$sessionid' $partner_where)", $db); if (mysql_num_rows($session_result) < 1) { if ($db = "cristina_tmp") { // echo "
No equipment was entered: Donor ID: '$donorid' / Session ID: '$sessionid'
\n"; } else { echo "
No such session Partner ID: '$partnerid' / Donor ID: '$donorid' / Session ID: '$sessionid'
\n"; } return; } else { $items_num = mysql_num_rows($session_result); } // // snag the proper referrer logo // $ref_array = get_link_ref($donor_info['link_ref']); $source_logo = $ref_array['source_logo']; $source_alt = $ref_array['source_alt']; // // donor name // if (trim($donor_info['company']) == "") { $donor_name = $donor_info['name']; } else { $donor_name = $donor_info['company']; } $receipt_query_done = false; $header_done = false; while ($session_info = mysql_fetch_assoc($session_result)) { // // date to display // if ($db == "cristina_tmp") { $date_header = "Entered"; $date_text = date("m\/d\/y", strtotime($session_info['date'])); } elseif ($session_info['placement_date'] != "") { $date_header = "Placement"; $date_text = date("m\/d\/y", strtotime($session_info['placement_date'])); } elseif ($session_info['match_date'] != "") { $date_header = "Matched"; $date_text = date("m\/d\/y", strtotime($session_info['match_date'])); } else { $date_header = "Pledged"; $date_text = date("m\/d\/y", strtotime($session_info['date'])); } if ($db == "cristina_tmp") { $session_sum_result = my_db_query("SELECT * FROM session_summary WHERE donorid = $donorid AND sessionid = '$sessionid'", $db); $session_array = mysql_fetch_assoc($session_sum_result); $pledge_date = date("F jS, Y, g:i a", strtotime($session_array['timestamp'])); } else { $pledge_date = date("F jS, Y, g:i a", strtotime($session_info['date'])); } if (!$header_done) { ?>
DONORID: 
 ,  
0) { $item_info = mysql_fetch_array($item_result); $item_desc = ""; $field_array = array("manufacturer", "manu_other", "model", "processor_type"); for ($i = 0; $i < sizeof($field_array); $i++) { $field_name = $field_array[$i]; if ($field_name == "model") { if ($item_desc != "") $item_desc .= ", "; $item_desc .= $item_info[$field_name]; } elseif ($item_info[$field_name] != "" && $field_name != "model") { if ($item_desc != "") $item_desc .= ", "; $item_result_b = my_db_query("SELECT option_text FROM form_options WHERE (option_value = '" . mysql_escape_string($item_info[$field_name]) . "' AND table_name = '{$session_info['table_name']}' AND field_name = '$field_name' AND display_when = '{$item_info['knowledge_path']}')"); $add_item_info = mysql_fetch_assoc($item_result_b); $item_desc .= $add_item_info['option_text']; } } } // } if ($format == "table_summary") { $receipt_value = "0"; $receipt_num = ""; if ($session_info['status'] == "complete" && !$receipt_query_done) { $receipt_result = my_db_query("SELECT * FROM receipt_values WHERE (donorid = $donorid AND sessionid = '$sessionid' AND partnerid = '$partnerid')", $db); $receipt_query_done = true; } @mysql_data_seek($receipt_result, 0); while ($receipt_info = @mysql_fetch_assoc($receipt_result)) { if ($receipt_info['table_name'] == $session_info['table_name'] && $receipt_info['itemid'] == $session_info['itemid']) { $receipt_value = $receipt_info['item_value']; $receipt_num = $receipt_info['receipt_id']; } } } $table_name = strtoupper(str_replace("_", " ", $session_info['table_name'])); ?> \n"; echo "
Pledge Started: {$pledge_date}\n"; if ($session_info['last_page'] == "contact.ncf" || $session_info['last_page'] == "") { // echo " Resume\n"; $resume_url = "contact.ncf?inventory=" . urlencode($inventory) . "&coming_from=welcome&returning_session=yes&link_ref=" . urlencode($link_ref) . "&send_info=" . urlencode($send_info) . "&sessionid=" . urlencode($session_array['sessionid']) . "&email=" . urlencode($donor_info['email']); } else { // echo " Resume\n"; $resume_url = "{$session_info['last_page']}?sessionid=" . urlencode($session_array['sessionid']) . "&donorid=" . urlencode($donorid); } echo "  \n"; echo "
\n"; echo " \n"; } else { ?>
 
Type  
 FMV 
 RCPT 
 
Item Desc  
  
   
 $ 
  
    
 
 
 $ 
 
 
Originally Pledged:  
  Resume This Donation  \n"; echo "

\n"; } } function get_link_ref($link_ref) { // // returns an array with: // // source_logo set to an image path // source_alt set to appropriate alt text // if ($link_ref == "MVI") { $source_logo = "images/list_logo/mvi_list_logo.png"; $source_alt = "Market Velocity referred donor..."; } else if ($link_ref == "Dell") { $source_logo = "images/list_logo/dell_list_logo.png"; $source_alt = "Dell referred donor..."; } else if ($link_ref == "MVI HP") { $source_logo = "images/list_logo/hp_list_logo.png"; $source_alt = "HP referred donor..."; } else if ($link_ref == "MVI Ingram") { $source_logo = "images/list_logo/ingram_list_logo.png"; $source_alt = "Ingram Micro referred donor..."; } else if ($link_ref == "Wacom") { $source_logo = "images/list_logo/wacom_list_logo.gif"; $source_alt = "Wacom referred donor..."; } else if ($link_ref == "PC Magazine") { $source_logo = "images/list_logo/pcmag_list_logo.gif"; $source_alt = "PC Magazine referred donor..."; } else if ($link_ref == "Dell Canada") { $source_logo = "images/list_logo/dell_canada_list_logo.png"; $source_alt = "Dell Canada referred donor..."; } else if ($link_ref == "Dell Canada Corporate") { $source_logo = "images/list_logo/dell_canada_list_logo.png"; $source_alt = "Dell Canada Corporate referred donor..."; } else if ($link_ref == "TigerDirect") { $source_logo = "images/list_logo/tigerdirect_list_logo.png"; $source_alt = "TigerDirect referred donor..."; } else if ($link_ref == "eBay Rethink") { $source_logo = "images/list_logo/ebay_list_logo.png"; $source_alt = "eBay referred donor..."; } else if ($link_ref == "Epson") { $source_logo = "images/list_logo/epson_list_logo.png"; $source_alt = "Epson referred donor..."; } else if ($link_ref == "Xerox") { $source_logo = "images/list_logo/xerox_list_logo.png"; $source_alt = "Xerox referred donor..."; } else if ($link_ref == "ASCII Group") { $source_logo = "images/list_logo/ascii_list_logo.png"; $source_alt = "ASCII Group referred donor..."; } else if ($link_ref == "CompTIA") { $source_logo = "images/list_logo/comptia_list_logo.png"; $source_alt = "CompTIA referred donor..."; } else if ($link_ref == "Veteran Program") { $source_logo = "images/list_logo/veteran_list_logo.png"; $source_alt = "Veteran Program referred donor..."; } else if ($link_ref == "Anheuser") { $source_logo = "images/list_logo/anheuser_list_logo.png"; $source_alt = "Anheuser-Busch referred donor..."; } else if ($link_ref == "Newspaper") { $source_logo = "images/list_logo/newspaper_list_logo.png"; $source_alt = "Newspaper referred donor..."; } else if ($link_ref == "Word of Mouth") { $source_logo = "images/list_logo/mouth_list_logo.png"; $source_alt = "Word of Mouth referred donor..."; } else if ($link_ref == "Internet Search") { $source_logo = "images/list_logo/google_list_logo.png"; $source_alt = "Internet Search referred donor..."; } else if ($link_ref == "Corporate%") { if (preg_match("/Morgan Stanley/i",$company)) { $source_logo = "images/list_logo/morgan_stanley_list_logo.png"; $source_alt = "Morgan Stanley referred donor..."; } else if (preg_match("/Honeywell/i",$company)) { $source_logo = "images/list_logo/honeywell_list_logo.png"; $source_alt = "Honeywell referred donor..."; } } else if (preg_match("/craters/i",$link_ref)) { $source_logo = "images/list_logo/craters_list_logo.png"; $source_alt = "{$link_ref} referred donor..."; } else if ($link_ref == "dTap" || $link_ref == "") { $source_logo = "images/list_logo/dtap_list_logo.png"; $source_alt = "dTap entry by staff..."; } else { $source_logo = "images/list_logo/default_list_logo.png"; $source_alt = "{$link_ref} referred donor..."; } if (preg_match("/Morgan Stanley/i",$company)) { $source_logo = "images/list_logo/morgan_stanley_list_logo.png"; $source_alt = "Morgan Stanley referred donor..."; } else if (preg_match("/Honeywell/i",$company)) { $source_logo = "images/list_logo/honeywell_list_logo.png"; $source_alt = "Honeywell referred donor..."; } if (!$source_logo) { $source_logo = "images/list_logo/default_list_logo.png"; $source_alt = "{$link_ref} referred donor..."; } $this_array['source_logo'] = $source_logo; $this_array['source_alt'] = $source_alt; return $this_array; } if (!function_exists('dollarformat')) { function dollarformat($input) { $weight = sprintf("%01.2f", $input); if ($input >= 0) { if (strlen($weight) == 12) $weight = substr($weight, -12, 3) . "," . substr($weight, -9, 3) . "," . substr($weight, -6, 6); elseif (strlen($weight) == 11) $weight = substr($weight, -11, 2) . "," . substr($weight, -9, 3) . "," . substr($weight, -6, 6); elseif (strlen($weight) == 10) $weight = substr($weight, -10, 1) . "," . substr($weight, -9, 3) . "," . substr($weight, -6, 6); elseif (strlen($weight) == 9) $weight = substr($weight, -9, 3) . "," . substr($weight, -6, 6); elseif (strlen($weight) == 8) $weight = substr($weight, -8, 2) . "," . substr($weight, -6, 6); elseif (strlen($weight) == 7) $weight = substr($weight, -7, 1) . "," . substr($weight, -6, 6); } else { if (strlen($weight) == 13) $weight = substr($weight, -13, 4) . "," . substr($weight, -9, 3) . "," . substr($weight, -6, 6); elseif (strlen($weight) == 12) $weight = substr($weight, -12, 3) . "," . substr($weight, -9, 3) . "," . substr($weight, -6, 6); elseif (strlen($weight) == 11) $weight = substr($weight, -11, 2) . "," . substr($weight, -9, 3) . "," . substr($weight, -6, 6); elseif (strlen($weight) == 10) $weight = substr($weight, -10, 4) . "," . substr($weight, -6, 6); elseif (strlen($weight) == 9) $weight = substr($weight, -9, 3) . "," . substr($weight, -6, 6); elseif (strlen($weight) == 8) $weight = substr($weight, -8, 2) . "," . substr($weight, -6, 6); } return $weight; }} if (!function_exists('cache_page')) { function cache_page($seconds = 10800) { // default = 3 hrs header('Expires: ' . gmdate('D, d M Y H:i:s',time()+$seconds) . ' GMT'); header("Cache-Control: max-age=$seconds"); header('Pragma:'); }} if (!function_exists('array_stripslashes')) { function array_stripslashes($value) { if (!is_array($value)) { return stripslashes($value); } else { return array_map("array_stripslashes",$value); } }} if (!function_exists('getNth')) { function getNth($n) { $qn = (int) (($n%100) / 10); $rn = $n % 10; $suffix = "th"; if ($qn != 1) { switch ($rn) { case 1: $suffix = "st"; break; case 2: $suffix = "nd"; break; case 3: $suffix = "rd"; break; } } return $n . $suffix; }} if (!function_exists('check_do_not_email')) { function check_do_not_email($address) { $address_on_blacklist = false; $res_to_check = preg_match_all("/[a-z0-9]+([+#\'_\\.-][a-z0-9]+)*@([a-z0-9]+([\.-][a-z0-9]+)*)+\\.[a-z]{2,}/i", strtolower(trim($address)), $matches_to_check); if (sizeof($GLOBALS['do_not_email_list'] < 1)) { $result = my_db_query("SELECT email FROM do_not_email"); if (mysql_numrows($result)) { while($do_not_email = mysql_fetch_assoc($result)) { $res = preg_match_all("/[a-z0-9]+([+#\'_\\.-][a-z0-9]+)*@([a-z0-9]+([\.-][a-z0-9]+)*)+\\.[a-z]{2,}/i", strtolower(trim($do_not_email['email'])), $matches); if ($res) { foreach(array_unique($matches[0]) as $email) { $GLOBALS['do_not_email_list'][] = strtolower(trim($email)); } } } } } if ($res_to_check && sizeof($GLOBALS['do_not_email_list']) > 0) { foreach(array_unique($matches_to_check[0]) as $email) { if (in_array($email, $GLOBALS['do_not_email_list'])) { $address_on_blacklist = true; } } } return $address_on_blacklist; }} if (!function_exists('count_tag_usage')) { function count_tag_usage() { $result_tags = my_db_query("SELECT DISTINCT concat(tag_id, '-', resource_table) as taginfo, tag_id, resource_table, count(id) AS count_id FROM `resource_tags_map` WHERE 1 GROUP BY taginfo ORDER BY count_id DESC"); while ($tag_info = mysql_fetch_assoc($result_tags)) { unset($count_column); if ($tag_info['resource_table'] == "resource_article") { $count_column = "article_count"; } elseif ($tag_info['resource_table'] == "resource_comment") { $count_column = "comment_count"; } elseif ($tag_info['resource_table'] == "resource_url") { $count_column = "url_count"; } elseif ($tag_info['resource_table'] == "resource_file") { $count_column = "file_count"; } elseif ($tag_info['resource_table'] == "resource_contact") { $count_column = "contact_count"; } elseif ($tag_info['resource_table'] == "resource_feedback") { $count_column = "feedback_count"; } elseif ($tag_info['resource_table'] == "resource_blog") { $count_column = "blog_count"; } elseif ($tag_info['resource_table'] == "resource_tags") { $count_column = "tag_count"; } elseif ($tag_info['resource_table'] == "partner_info") { $count_column = "partner_count"; } elseif ($tag_info['resource_table'] == "donor_info") { $count_column = "donor_count"; } if ($count_column != "") { my_db_query("UPDATE resource_tags SET {$count_column} = {$tag_info['count_id']} WHERE id = {$tag_info['tag_id']}"); } } }} if (!function_exists('filter_xss')) { function filter_xss($val) { if (is_array($val)) { foreach ($val as $key => $value) { $val[$key] = filter_xss($value); } } else { // remove all non-printable characters. CR(0a) and LF(0b) and TAB(9) are allowed // this prevents some character re-spacing such as // note that you have to handle splits with \n, \r, and \t later since they *are* allowed in some inputs $val = preg_replace('/([\x00-\x08,\x0b-\x0c,\x0e-\x19])/', '', $val); // straight replacements, the user should never need these since they're normal characters // this prevents like $search = 'abcdefghijklmnopqrstuvwxyz'; $search .= 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; $search .= '1234567890!@#$%^&*()'; $search .= '~`";:?+/={}[]-_|\'\\'; for ($i = 0; $i < strlen($search); $i++) { // ;? matches the ;, which is optional // 0{0,7} matches any padded zeros, which are optional and go up to 8 chars // @ @ search for the hex values $val = preg_replace('/(&#[xX]0{0,8}'.dechex(ord($search[$i])).';?)/i', $search[$i], $val); // with a ; // @ @ 0{0,7} matches '0' zero to seven times $val = preg_replace('/(�{0,8}'.ord($search[$i]).';?)/', $search[$i], $val); // with a ; } // now the only remaining whitespace attacks are \t, \n, and \r $ra1 = Array('javascript', 'vbscript', 'expression', 'applet', 'meta', 'xml', 'blink', 'link', 'style', 'script', 'embed', 'object', 'iframe', 'frame', 'frameset', 'ilayer', 'layer', 'bgsound', 'title', 'base'); $ra2 = Array('onabort', 'onactivate', 'onafterprint', 'onafterupdate', 'onbeforeactivate', 'onbeforecopy', 'onbeforecut', 'onbeforedeactivate', 'onbeforeeditfocus', 'onbeforepaste', 'onbeforeprint', 'onbeforeunload', 'onbeforeupdate', 'onblur', 'onbounce', 'oncellchange', 'onchange', 'onclick', 'oncontextmenu', 'oncontrolselect', 'oncopy', 'oncut', 'ondataavailable', 'ondatasetchanged', 'ondatasetcomplete', 'ondblclick', 'ondeactivate', 'ondrag', 'ondragend', 'ondragenter', 'ondragleave', 'ondragover', 'ondragstart', 'ondrop', 'onerror', 'onerrorupdate', 'onfilterchange', 'onfinish', 'onfocus', 'onfocusin', 'onfocusout', 'onhelp', 'onkeydown', 'onkeypress', 'onkeyup', 'onlayoutcomplete', 'onload', 'onlosecapture', 'onmousedown', 'onmouseenter', 'onmouseleave', 'onmousemove', 'onmouseout', 'onmouseover', 'onmouseup', 'onmousewheel', 'onmove', 'onmoveend', 'onmovestart', 'onpaste', 'onpropertychange', 'onreadystatechange', 'onreset', 'onresize', 'onresizeend', 'onresizestart', 'onrowenter', 'onrowexit', 'onrowsdelete', 'onrowsinserted', 'onscroll', 'onselect', 'onselectionchange', 'onselectstart', 'onstart', 'onstop', 'onsubmit', 'onunload'); $ra = array_merge($ra1, $ra2); $found = true; // keep replacing as long as the previous round replaced something while ($found == true) { $val_before = $val; for ($i = 0; $i < sizeof($ra); $i++) { $pattern = '/'; for ($j = 0; $j < strlen($ra[$i]); $j++) { if ($j > 0) { $pattern .= '('; $pattern .= '(&#[xX]0{0,8}([9ab]);)'; $pattern .= '|'; $pattern .= '|(�{0,8}([9|10|13]);)'; $pattern .= ')*'; } $pattern .= $ra[$i][$j]; } $pattern .= '/i'; $replacement = substr($ra[$i], 0, 2).''.substr($ra[$i], 2); // add in <> to nerf the tag $val = preg_replace($pattern, $replacement, $val); // filter out the hex tags if ($val_before == $val) { // no replacements were made, so exit the loop $found = false; } } } } return $val; }} // // works better on large files than get_file_contents // if (!function_exists('curl_get_file_contents')) { function curl_get_file_contents($URL) { $c = curl_init(); curl_setopt($c, CURLOPT_RETURNTRANSFER, 1); curl_setopt($c, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($c, CURLOPT_URL, $URL); $contents = curl_exec($c); curl_close($c); if ($contents) return $contents; else return FALSE; }} // // function to generate a random string // if (!function_exists('gen_random_string')) { function gen_random_string($length=5) { $characters = "23456789abcdefghjkmnpqrstuvwxyz"; $string = ""; for ($p = 0; $p < $length; $p++) { $string .= $characters[mt_rand(0, strlen($characters))]; } return $string; }} // // display / manage phone verification // if (!function_exists('display_phone_verification_status')) { function display_phone_verification_status($phone_area, $phone_prefix, $phone_suffix, $phone_ext = "", $scope = "default", $id = "") { global $userdata; global $user; if ($userdata && !$user) $user = $userdata; $phone_area = trim($phone_area); $phone_prefix = trim($phone_prefix); $phone_suffix = trim($phone_suffix); $phone_ext = trim($phone_ext); if (($user->data['is_admin'] || $user->data['is_semi_admin']) && ($phone_area != "" && $phone_prefix != "" && $phone_suffix != "")) { $div_id = "phoneverify_" . mt_rand(0,10000) . "_{$phone_area}{$phone_prefix}{$phone_suffix}{$phone_ext}"; $whole_number = "{$phone_area}-{$phone_prefix}-{$phone_suffix}"; if ($phone_ext != "") $whole_number .= " x{$phone_ext}"; echo "\n"; $result = my_db_query("SELECT ts_approved, approved_by FROM verified_phone_numbers WHERE phone_area='{$phone_area}' AND phone_prefix='{$phone_prefix}' AND phone_suffix='{$phone_suffix}' AND phone_ext='{$phone_ext}'"); if (mysql_numrows($result)) { // // is verified! display green checkbox or something? // $info = mysql_fetch_assoc($result); echo "
"; } else { // // not verified! display red checkbox with code to trigger an insert... // echo "
"; } echo "
\n"; } }} // // protected areas... // if (preg_match("/\/ncf\//i", $_SERVER['PHP_SELF']) && $ajax_auth != "ncfpass") { require_once("session.inc"); } if (preg_match("/\/surveys/i", $_SERVER['PHP_SELF']) || preg_match("/\/scheduled_process/i", $_SERVER['PHP_SELF']) || preg_match("/surveys/i", $key) || (preg_match("/showgraph/i", $_SERVER['PHP_SELF']))) { require("surveys-fx.inc"); } ?>

Use this interactive map to locate and learn about the nonprofit refurbishers and recyclers in your area.


Map Locator admin 2018-09-04T19:14:19+00:00

LEARN MORE

  • Home
  • Map Locator
  • About Us
    • About Us
    • Advisory Council
    • Member’s Pledge
    • Become a Member
    • Right to Repair
  • Contact us
Copyright 2012 -  | All Rights Reserved | A Project of Digitunity