'.petition_help('node/add#petition').'

'; case 'admin/petition': return '

'.t('You can view statistics about your petitions below.').'

'; case 'admin/petition/comments/'.arg(3): return '

'.t('The following comments have been left about this petition:').'

'; case 'admin/petition/signatories/'.arg(3): return '

'.t('The following people have signed this petition:').'

'; case 'admin/petition/trending/'.arg(3): return '

'.t('The following is the number of people who signed this petition for each week:').'

'; } } /** * Implementation of hook_perm(). */ function petition_perm() { return array('create petition', 'respond to petition', 'access petition stats'); } /** * Implementation of hook_menu(). */ function petition_menu($may_cache) { $items = array(); if ($may_cache) { $items[] = array('title' => t('petition'), 'path' => 'node/add/petition', 'access' => user_access('create petition'), ); $items[] = array('title' => t('petitions'), 'path' => 'petition', 'callback' => 'petition_overview', 'access' => user_access('respond to petition'), ); $items[] = array('title' => t('petition statistics'), 'path' => 'admin/petition', 'callback' => 'petition_results_overview', 'access' => user_access('access petition stats'), ); $items[] = array('title' => t('comments'), 'path' => 'admin/petition/comments', 'callback' => 'petition_results_comments', 'access' => user_access('access petition stats'), 'type' => MENU_CALLBACK, ); $items[] = array('title' => t('signatories'), 'path' => 'admin/petition/signatories', 'callback' => 'petition_results_signatories', 'access' => user_access('access petition stats'), 'type' => MENU_CALLBACK, ); $items[] = array('title' => t('signatories (csv)'), 'path' => 'admin/petition/signatories/csv', 'callback' => 'petition_results_signatories_csv', 'access' => user_access('access petition stats'), 'type' => MENU_CALLBACK, ); $items[] = array('title' => t('trending'), 'path' => 'admin/petition/trending', 'callback' => 'petition_results_trending', 'access' => user_access('access petition stats'), 'type' => MENU_CALLBACK, ); } return $items; } /** * Implementation of hook_node_info(). */ function petition_node_info() { return array('petition' => array('name' => t('petition'), 'base' => 'petition')); } /** * Implementation of hook_access(). */ function petition_access($op, $node) { global $user; if ($op == 'create') { return user_access('create petition'); } if ($op == 'update' || $op == 'delete') { if (user_access('edit petition') && ($user->uid == $node->uid)) { return TRUE; } } } /** * Implementation of hook_form(). */ function petition_form(&$node) { civicrm_initialize(TRUE); $form['title'] = array( '#type' => 'textfield', '#title' => t('Title'), '#required' => TRUE, '#default_value' => $node->title, ); $form['target'] = array( '#type' => 'textfield', '#title' => t('Target'), '#default_value' => $node->target, '#description' => t('The number of responses you are looking for from this petition.'), '#required' => TRUE, ); $form['body'] = array( '#type' => 'textarea', '#title' => t('Body'), '#default_value' => $node->body, '#description' => t('The petition itself: what it is users are going to be supporting.'), '#required' => TRUE, '#rows' => 20, ); $form['appeal'] = array( '#type' => 'textarea', '#title' => t('Appeal'), '#default_value' => $node->appeal, '#description' => t('Explain why the petition is important and appeal to the users on why they should sign.'), '#required' => TRUE, '#rows' => 20, ); $form['personal'] = array( '#type' => 'textarea', '#title' => t('Personal Message'), '#default_value' => $node->personal, '#description' => t('An optional personal message, usually from the petition creators themselves.'), '#rows' => 20, ); $form['statistics'] = array( '#type' => 'radios', '#title' => t('Display Signee Statistics'), '#default_value' => ($node->statistics ? $node->statistics : 0), '#options' => array(t('No'), t('Yes')), '#description' => t('Controls whether or not public users can see the number of people who have signed this petition.'), '#required' => TRUE, ); $form['defaultibles'] = array( '#type' => 'fieldset', '#collapsible' => TRUE, '#title' => t('Default Petition Settings'), '#description' => t('If these settings are unchanged, they will use the defaults set by the administrator.'), ); $form['defaultibles']['thank_you_page'] = array( '#type' => 'textfield', '#title' => t('"Thank You" Page'), '#default_value' => $node->thank_you_page, '#description' => t('The path in your site to which users will be taken after completing a petition.'), ); // emails enabled, so allow message customization. if (variable_get('petition_default_autorespond', 1)) { $profile_fields = _petition_adjust_fields(crm_uf_get_profile_fields(variable_get('petition_profile', 1))); $wildcards = array('%petition_title'); // we'll use the node->title here when it comes time. foreach ($profile_fields as $key => $value) { $wildcards[] = "%$key"; } $wildcards = implode(', ', $wildcards); // for #description display. $form['defaultibles']['autorespond_from'] = array( '#type' => 'textfield', '#title' => t('Email Auto-Respond From'), '#default_value' => $node->autorespond_from, '#description' => t('Enter the email address that will appear in the "From: " header of sent messages.'), ); $form['defaultibles']['autorespond_subject'] = array( '#type' => 'textfield', '#title' => t('Email Auto-Respond Subject'), '#default_value' => $node->autorespond_subject, '#description' => t('Subject of auto-response email message to be sent. You may include the following wildcards: %wild.', array('%wild' => $wildcards)), ); $form['defaultibles']['autorespond_message'] = array( '#type' => 'textarea', '#title' => t('Email Auto-Respond Message'), '#default_value' => $node->autorespond_message, '#description' => t('Body of auto-response email message to be sent. You may include the following wildcards: %wild.', array('%wild' => $wildcards)), ); } // the same format applies to all our boxes. $form['filter'] = filter_form($node->format); return $form; } /** * Implementation of hook_insert(). */ function petition_insert($node) { db_query("INSERT INTO {petition} (nid, appeal, personal, target, statistics, thank_you_page, autorespond_from, autorespond_subject, autorespond_message) VALUES (%d, '%s', '%s', %d, %d, '%s', '%s', '%s', '%s')", $node->nid, $node->appeal, $node->personal, $node->target, $node->statistics, $node->thank_you_page, $node->autorespond_from, $node->autorespond_subject, $node->autorespond_message); } /** * Implementation of hook_update(). */ function petition_update($node) { db_query("UPDATE {petition} SET appeal = '%s', personal = '%s', target = %d, statistics = %d, thank_you_page = '%s', autorespond_from = '%s', autorespond_subject = '%s', autorespond_message = '%s' WHERE nid = %d", $node->appeal, $node->personal, $node->target, $node->statistics, $node->thank_you_page, $node->autorespond_from, $node->autorespond_subject, $node->autorespond_message, $node->nid); } /** * Implementation of hook_delete(). */ function petition_delete($node) { db_query('DELETE FROM {petition} WHERE nid = %d', $node->nid); } /** * Implementation of hook_load(). */ function petition_load($node) { $content = db_fetch_object(db_query('SELECT * FROM {petition} WHERE nid = %d', $node->nid)); if ($node->nid) { $content->signatures = petition_count_signatures($node->nid); } return $content; } /** * Implementation of hook_view(). */ function petition_view(&$node, $teaser = FALSE, $page = FALSE) { civicrm_initialize(TRUE); // generate the signup form. forms only support textfields. $profile_id = variable_get('petition_profile', 1); $fields = crm_uf_get_profile_fields($profile_id, true); foreach ($fields as $row) { if ($row['where'] == 'civicrm_state_province.name' || $row['where'] == 'civicrm_country.name') { $country_options = $row['is_required'] ? CRM_Core_PseudoConstant::country() : array('' => '<'.t('none').'>') + CRM_Core_PseudoConstant::country(); $state_options = $row['is_required'] ? CRM_Core_PseudoConstant::stateProvince() : array('' => '<'.t('none').'>') + CRM_Core_PseudoConstant::stateProvince(); $form[$row['name']] = array( '#type' => 'select', '#title' => $row['title'], '#required' => $row['is_required'], '#options' => $row['where'] == 'civicrm_state_province.name' ? $state_options : $country_options, ); } else { $form[$row['name']] = array( '#type' => 'textfield', '#title' => t($row['title']), '#required' => $row['is_required'], '#default_value' => $edit[$row['name']] ); } } $form['comment'] = array( '#type' => 'textarea', '#title' => t('Your comment to leaders and the press') ); $form['pid'] = array( '#type' => 'hidden', '#value' => $node->nid, ); $form['submit'] = array( '#type' => 'submit', '#value' => t('Submit'), ); $node->petition_signup_form = drupal_get_form('petition_signup_form_data', $form); $node->body = check_markup($node->body, $node->format, FALSE); $node->teaser = check_markup($node->teaser, $node->format, FALSE); $node->appeal = check_markup($node->appeal, $node->format, FALSE); $node->personal = $node->personal ? check_markup($node->personal, $node->format, FALSE) : NULL; $node->body = theme('petition_view', $node); } /** * Signs a user up for a petition, creates new contacts where appropriate * and registers the contacts with a group before creating an activity record * indicating he or she signed the petition. */ function petition_signup_form_data_submit($form_id, $form_values) { civicrm_initialize(TRUE); $node = node_load($form_values['pid']); $cid = 0; // if existing user, it'll be their cid. // adjust petition fields to remove underscore + numbers. $form_values = _petition_adjust_fields($form_values); // search to see if this was an existing contact. by default, we only // based on email. @todo someday, this should be user configurable. $crm_field_list = array('email'); $crm_fields = array('email' => $form_values['email']); $contact_check = crm_contact_search($crm_fields, $crm_field_list); // contact_search returns an array of matches. // need to make sure we only found one person. if (count($contact_check[0]) > 0) { $cid = array_shift($contact_check[0]); $cid = $cid['contact_id']; } // new user. if ($cid == 0) { $form_values['country_id'] = isset($form_values['country']) ? $form_values['country'] : NULL; $form_values['state_province_id'] = isset($form_values['state_province']) ? $form_values['state_province'] : NULL; $new = crm_create_contact($form_values, 'Individual'); $cid = $new->id; } // load the full user object, which now exists regardless // of whether the user existed already, or is brand new. $contact = crm_get_contact(array('contact_id' => $cid)); $contact->contact_id = $contact->id; // add this contact to a group, if enabled. if (variable_get('petition_group_signup', 1)) { $groups = variable_get('petition_group', array()); foreach ($groups as $group) { $contacts_to_add = array('0' => $contact); $thisgroup = crm_get_groups(array('id' => $group)); crm_add_group_contacts($thisgroup[0], $contacts_to_add); } } // insert activity record. $activity_params = array( 'entity_table' => 'civicrm_contact', 'entity_id' => $cid, 'activity_type' => t('Signed Petition: %title', array('%title' => $node->title)), 'module' => t('Petition'), 'activity_id' => $node->nid, 'activity_summary' => t('This contact signed the %title petition.', array('%title' => $node->title)), 'activity_date' => date('YmdHis') ); crm_create_activity_history($activity_params); // record the contact id, petition id, and any comments. petition_register_signatory($node->nid, $cid, $form_values['comment']); // send an autoreply email if enabled. if (variable_get('petition_default_autorespond', 1) && $form_values['email']) { $wildcards = _petition_adjust_fields(crm_uf_get_profile_fields(variable_get('petition_profile', 1))); foreach ($wildcards as $key => $field) { $wildcards["%$key"] = $form_values[$key]; unset($wildcards[$key]); } $wildcards['%petition_title'] = $node->title; $from = $node->autorespond_from ? $node->autorespond_from : variable_get('site_mail', ini_get('sendmail_from')); $subject = $node->autorespond_subject ? $node->autorespond_subject : variable_get('petition_default_autorespond_subject', t('Thanks for signing %petition_title')); $message = $node->autorespond_message ? $node->autorespond_message : variable_get('petition_default_autorespond_message', t('Thanks for signing this petition, %first_name!')); $headers = "From: $from\nReply-to: $from\nX-Mailer: Drupal\nReturn-path: $from\nErrors-to: $from"; user_mail($form_values['email'], t($subject, $wildcards), t($message, $wildcards), $headers); } // and send 'em along home, danno. drupal_set_message(t('Thank you for signing the petition.')); $thank_you = $node->thank_you_page ? $node->thank_you_page : variable_get('petition_default_goto_page', 'node'); drupal_goto($thank_you); } /** * Registers that a user has signed a petition. */ function petition_register_signatory($pid, $cid, $comment = NULL) { $check_sql = db_query("SELECT cid FROM {petition_signatories} WHERE cid = %d AND pid = %d", $cid, $pid); if (db_num_rows($check_sql) == 0) { $sql = db_query("INSERT INTO {petition_signatories} (pid, cid, created, comment) VALUES (%d, %d, %d, '%s')", $pid, $cid, time(), $comment); } } /** * Displays the entire petition to the user. */ function theme_petition_view($node) { theme_add_style(drupal_get_path('module', 'petition').'/petition.css'); $output = '
'; if ($node->statistics) { $output .= '
'; $output .= t('%signatures of %target people have signed this petition.', array('%signatures' => $node->signatures, '%target' => $node->target)); $output .= '
'; } $output .= '
'.$node->appeal.'
'; $output .= '
'.$node->body.'
'; // if there is no personal message, our form takes up the width of the // entire page. If this is, however, then wel split the page in two // columns (via CSS): one for the signup form, and another for the message. if (!$node->personal) { $output .= '
'.$node->petition_signup_form.'
'; } else { $output .= '
'; $output .= '
'.$node->personal.'
'; $output .= '
'.$node->petition_signup_form.'
'; $output .= '
'; } $output .= '
'; return $output; } /** * Displays a list of active petitions. */ function petition_overview() { $results = db_query('SELECT n.nid FROM {petition} p JOIN {node} n ON p.nid = n.nid'); while ($row = db_fetch_object($results)){ $content .= theme('petition_overview', node_load($row->nid)); } return $content ? $content : t('No petitions have been defined.'); } /** * Displays a petition on the petition overview page. */ function theme_petition_overview($node) { $output = '
'; $output .= '

'.l($node->title, 'node/'.$node->nid).'

'; $output .= '
'.$node->appeal.'
'; $output .= '
'.l(t('read more'), 'node/'.$node->nid).'
'; $output .= '
'; return $output; } /** * Implementation of hook_settings(). */ function petition_settings() { civicrm_initialize(true); $form['petition'] = array( '#type' => 'fieldset', '#title' => t('Default Settings'), ); $form['petition']['petition_default_goto_page'] = array( '#type' => 'textfield', '#title' => t('Default "Thank You" Page'), '#default_value' => variable_get('petition_default_goto_page', 'node'), '#description' => t('Enter the page users will be taken to after they sign a petition. This option can be overridden at the petition level.'), ); $form['petition']['petition_default_autorespond'] = array( '#type' => 'radios', '#title' => t('Default Email Auto-Respond'), '#options' => array(t('No'), t('Yes')), '#default_value' => variable_get('petition_default_autorespond', 1), '#description' => t('Should petitions submitted through this site send an email auto-response to the signer?'), ); // wildcards, like %thing, can be used to customize the email autoresponse. $profile_fields = _petition_adjust_fields(crm_uf_get_profile_fields(variable_get('petition_profile', 1))); $wildcards = array('%petition_title'); // we'll use the node->title here when it comes time. foreach ($profile_fields as $key => $value) { $wildcards[] = "%$key"; } $wildcards = implode(', ', $wildcards); // for #description display. $form['petition']['petition_default_autorespond_subject'] = array( '#type' => 'textfield', '#title' => t('Default Email Auto-Respond Subject'), '#default_value' => variable_get('petition_default_autorespond_subject', t('Thanks for signing %petition_title')), '#description' => t('Subject of auto-response email message to be sent. You may include the following wildcards: %wild.', array('%wild' => $wildcards)), ); $form['petition']['petition_default_autorespond_message'] = array( '#type' => 'textarea', '#title' => t('Default Email Auto-Respond Message'), '#default_value' => variable_get('petition_default_autorespond_message', t('Thanks for signing this petition, %first_name!')), '#description' => t('Body of auto-response email message to be sent. You may include the following wildcards: %wild.', array('%wild' => $wildcards)), ); $form['civicrm'] = array( '#type' => 'fieldset', '#title' => t('Petition to CiviCRM Settings'), '#description' => t('The Petition module integrates directly into CiviCRM using profile fields set up by an administrator. It also notates contacts when they sign a petition by (optionally) adding them to a group and then adding an action to their record.'), ); $form['civicrm']['petition_group_signup'] = array( '#type' => 'radios', '#title' => t('Sign Users Up to Groups'), '#default_value' => variable_get('petition_group_signup', 1), '#options' => array(t('No'), t('Yes')), '#description' => t('Controls whether or not contacts are added to groups as a result of signing a petition.'), '#required' => TRUE, ); // Build select for groups. $group_options = array(); $groups = crm_get_groups(); $i = 0; while ($i < count($groups) ) { $group_options[$groups[$i]->id] = $groups[$i]->name; ++$i; } $form['civicrm']['petition_group'] = array( '#type' => 'select', '#title' => t('Signer Groups'), '#default_value' => variable_get('petition_group', NULL), '#options' => $group_options, '#description' => t('Select the CiviCRM group(s) with which to associate petition signers.'), '#multiple' => TRUE, ); // Build select for profiles. $profile_options = array(); $profiles = crm_uf_get_profile_groups(); foreach ($profiles as $key => $profile) { $profile_options[$key] = $profile; } $form['civicrm']['petition_profile'] = array( '#type' => 'select', '#title' => t('Signup Profile'), '#default_value' => variable_get('petition_profile', NULL), '#options' => $profile_options, '#description' => t('Select the CiviCRM profile for petition signers to use.'), ); $form['civicrm']['petition_location_type'] = array( '#type' => 'select', '#title' => t('Location Type'), '#default_value' => variable_get('petition_location_type', NULL), '#options' => _petition_location_types(), '#description' => t('Select a default location for petitioner info.'), ); return $form; } /** * Overview of all petitions. */ function petition_results_overview() { $rows = array(); $headers = array(t('Title'), t('Comments'), t('Signatures'), t('Operations')); $results = pager_query('SELECT nid FROM {petition}', 50); while ($result = db_fetch_object($results)) { // we'll load in the count and the entire node itself. $count = db_query('SELECT COUNT(*) AS total FROM {petition_signatories} WHERE pid = %s AND comment != ""', $result->nid); $node = node_load($result->nid); $count = db_fetch_object($count); $rows[] = array( $node->title, $count->total, petition_count_signatures($node->nid).' '.t('(of %target)', array('%target' => $node->target)), l(t('Signatories'), 'admin/petition/signatories/'.$node->nid) .' | '. l(t('Trending'), 'admin/petition/trending/'.$node->nid) .' | '. l(t('Comments'), 'admin/petition/comments/'.$node->nid) ); } $output .= theme('table', $headers, $rows); $output .= theme('pager', NULL, 50, 0); return $output; } /** * Display petition comments. */ function petition_results_comments($pid = NULL) { if (!is_numeric($pid)) { return NULL; } // no numbah, no winnings. $headers = array(t('ID'), t('Comment')); $results = pager_query('SELECT cid, comment FROM {petition_signatories} WHERE pid = %d AND comment != ""', 25, 0, NULL, $pid); while ($result = db_fetch_object($results)) { // an ID is displayed which links to the civicrm record. $rows[] = array(l($result->cid, "civicrm/contact/view", NULL, 'cid='.$result->cid), $result->comment); } if (count($rows) == 0) { // no data, no happy ending! $rows[] = array(array('data' => t('No records were found.'), 'colspan' => 2)); } $output .= theme('table', $headers, $rows); $output .= theme('pager', NULL, 25, 0); return $output; } /** * Signatories for a specific petition. */ function petition_results_signatories($pid = NULL) { civicrm_initialize(true); $node = node_load($pid); // return a list of fields used in the petition signup form. $profile_fields = _petition_adjust_fields(crm_uf_get_profile_fields(variable_get('petition_profile', 1))); // set up headers for the table. $return_properties = array(); $headers = array(t('ID')); foreach ($profile_fields as $key => $value) { $headers[] = $value['title']; $return_properties[$key]++; } $headers[] = t('Date Signed'); $rows = array(); $results = pager_query("SELECT cid, created FROM {petition_signatories} WHERE pid = %d ORDER BY created", 50, 0, NULL, $pid); while ($result = db_fetch_object($results)) { $row = array(); // for this row only. $search_params = array('id' => $result->cid); $match = array_shift(crm_contact_search($search_params, $return_properties)); $row[] = l($result->cid, "civicrm/contact/view", NULL, 'cid='.$result->cid); foreach ($return_properties as $key => $value) { $row[] = $match[$result->cid][$key]; } $row[] = format_date($result->created, 'small'); $rows[] = $row; } $output = '

'.$node->title.'

'; $output .= l(t('Export this petition in CSV format'), 'admin/petition/signatories/csv/'.$pid); $output .= theme('table', $headers, $rows); $output .= theme('pager', NULL, 50); return $output; } /** * Displays a trending report. */ function petition_results_trending($pid = NULL) { civicrm_initialize(true); $rows = array(); $headers = array(t('Week Starting'), t('Signatures'), t('Trend')); $results = db_query('SELECT COUNT(DISTINCT(cid)) AS signups, MAKEDATE(YEAR(NOW()), (WEEK(FROM_UNIXTIME(created)) * 7)-6) AS week_starting FROM {petition_signatories} WHERE pid = %d GROUP BY week_starting', $pid); $old_val = 0; while ($result = db_fetch_object($results)) { $row = array(); $row['week_starting'] = $result->week_starting; $row['signatures'] = $result->signups; $row['trend'] = ($result->signups > $old_val) ? theme('petition_trend', 'pos', '+' . ($result->signups - $old_val)) : theme('petition_trend', 'neg', '-' . ($old_val - $result->signups)); $old_val = $result->signups; $rows[] = $row; } $node = node_load($pid); $output = '

'.$node->title.'

'; $output .= theme('table', $headers, $rows); return $output; } /** * Themes the +/- of a trend report. * */ function theme_petition_trend($trend = 'pos', $data) { theme_add_style(drupal_get_path('module', 'petition').'/petition.css'); $output = ($trend == 'pos') ? '' : ''; $output .= "$data"; return $output; } /** * Returns number of a petition's signatures. */ function petition_count_signatures($pid = NULL) { $count = db_fetch_object(db_query("SELECT COUNT(cid) AS total FROM {petition_signatories} WHERE pid = %d", $pid)); return $count->total; } /** * Signatories for a specific petition, exported as a CSV file * @param arg1 Petition ID * @return CSV File */ function petition_results_signatories_csv($arg1) { $sort = $_GET; civicrm_initialize(true); $petition = node_load($arg1); // return a list of fields used in the petition signup form // turn the fields into headers on the form $dat = crm_uf_get_profile_fields ( variable_get('petition_profile', 1) ); $dat = _petition_adjust_fields($dat); // set up headers for the table // and fields for the CRM contact search foreach ($dat as $key => $field) { $header[] = $field['title']; $fields[$key] = 1; } $header[] = t('Contact ID'); $header[] = t('Date Signed'); $headers = $header; $rows = array(); $sql = db_query(db_rewrite_sql("SELECT DISTINCT(cid), created FROM {petition_signatories} WHERE pid = %d ORDER BY created"), $arg1); while($row = db_fetch_object($sql)){ $con_data = array(); $params = array( 'id' => $row->cid ); $return_properties = array( "sort_name"=>1, "email"=>1 ); $result = crm_contact_search( $params, $fields ); foreach($fields as $key => $value){ $signer[$key] = $result[0][$row->cid][$key]; } $signer['cid'] = $row->cid; $signer['created'] = $row->created; $rows[] = $signer; } $filename = str_replace(' ', '_', $petition->title) .'_'. date("Y-m-d"). '.csv'; $now = gmdate('D, d M Y H:i:s') . ' GMT'; $mime_type = 'text/x-csv'; $ext = 'csv'; // send the write header statements to the browser header('Content-Type: ' . $mime_type); header('Expires: ' . $now); // lem9 & loic1: IE need specific headers $isIE = strstr( $_SERVER['HTTP_USER_AGENT'], 'MSIE' ); if ( $isIE ) { header('Content-Disposition: inline; filename="' . $filename . '"'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); } else { header('Content-Disposition: attachment; filename="' . $filename . '"'); header('Pragma: no-cache'); } $result = ''; $seperator = ','; $enclosed = '"'; $escaped = $enclosed; $add_character = "\015\012"; $schema_insert = ''; foreach ( $headers as $field ) { if ($enclosed == '') { $schema_insert .= stripslashes($field); } else { $schema_insert .= $enclosed . str_replace($enclosed, $escaped . $enclosed, stripslashes($field)) . $enclosed; } $schema_insert .= $seperator; } // end while // need to add PMA_exportOutputHandler functionality out here, rather than // doing it the moronic way of assembling a buffer $out = trim(substr($schema_insert, 0, -1)) . $add_character; echo $out; $i = 0; $fields_cnt = count($headers); foreach ( $rows as $row ) { $schema_insert = ''; foreach ( $row as $j => $value ) { if (!isset($value) || is_null($value)) { $schema_insert .= ''; } else if ($value == '0' || $value != '') { // loic1 : always enclose fields $value = ereg_replace("\015(\012)?", "\012", $value); if ($enclosed == '') { $schema_insert .= $value; } else { $schema_insert .= $enclosed . str_replace($enclosed, $escaped . $enclosed, $value) . $enclosed; } } else { $schema_insert .= ''; } if ($j < $fields_cnt-1) { $schema_insert .= $seperator; } } // end foreach $out = $schema_insert . $add_character; echo $out; ++$i; } // end for } /** * Returns a set of fields with the dash number removed for insertion into CiviCRM * @return array */ function _petition_adjust_fields($edit) { $new_data = array(); foreach ($edit as $key => $value) { $check = split('-', $key); if(sizeof($check) > 1){ $new_key = $check[0]; } else { $new_key = $key; } $new_data[$new_key] = $edit[$key]; } return $new_data; } /** * Hardwired into CiviCRM. Integer values are undocumented, * but used several places in the app. Likely to break soon. * @return array */ function _petition_location_types(){ return array( 1 => t('Home'), 2 => t('Work'), 3 => t('Main'), 4 => t('Other)' ); }