/[drupal]/contributions/modules/ipAuthenticator/ipauth.module
ViewVC logotype

Diff of /contributions/modules/ipAuthenticator/ipauth.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.8, Tue Mar 17 14:21:02 2009 UTC revision 1.9, Wed Apr 8 17:42:22 2009 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id$  // $Id: ipauth.module,v 1.8 2009/03/17 14:21:02 jonfrancisskydiver Exp $
3  /**  /**
4   * @file   * @file
5   * Module code for an IP based authenticator   * Module code for an IP based authenticator
# Line 267  function ipauth_import_export($form_stat Line 267  function ipauth_import_export($form_stat
267    
268    $form['export_fieldset'] = array(    $form['export_fieldset'] = array(
269      '#type' => 'fieldset',      '#type' => 'fieldset',
270      '#title' => t('Export IP Authenticators to a CVS file'),      '#title' => t('Export IP Authenticators to a CSV file'),
271      '#description' => t('This will cause you to download a CVS file containing all IP Authenticators.'),      '#description' => t('This will cause you to download a CSV file containing all IP Authenticators.'),
272      '#weight' => 1,      '#weight' => 1,
273    );    );
274    $form['export_fieldset']['export'] = array(    $form['export_fieldset']['export'] = array(
# Line 277  function ipauth_import_export($form_stat Line 277  function ipauth_import_export($form_stat
277    );    );
278    $form['import_fieldset'] = array(    $form['import_fieldset'] = array(
279      '#type' => 'fieldset',      '#type' => 'fieldset',
280      '#title' => t('Import IP Authenticators from a CVS file'),      '#title' => t('Import IP Authenticators from a CSV file'),
281      '#description' => t('This import function simply appends authenticators. The feature doesn\'t care about duplicate entries.'). '<br>' .      '#description' => t('This import function simply appends authenticators. The feature doesn\'t care about duplicate entries.'). '<br>' .
282                        t('The format of the CVS file is as follows: '),                        t('The format of the CSV file is as follows: '),
283      '#weight' => 0      '#weight' => 0
284    );    );
285    $form['import_fieldset']['import'] = array(    $form['import_fieldset']['import'] = array(
286      '#type' => 'file',      '#type' => 'file',
287      '#title' => t('Upload the CVS file'),      '#title' => t('Upload the CSV file'),
288      '#size' => 48,      '#size' => 48,
289      '#description' => t('This will import all the IP Authenticator\'s in the CVS file to the database.')      '#description' => t('This will import all the IP Authenticator\'s in the CSV file to the database.')
290      );
291      $form['import_fieldset']['belowmarkup'] = array(
292        'value' => t('The format of the CSV file is as follows:') .'<Br/>' .
293                   t('"Row ID","Drupal User ID","Unsigned Int of IP","Unsigned Int of IP","description","0 for disabledm, or 1 for enabled","unix timestamp"') ."<br/>",
294    
295    );    );
296    $form['import_fieldset']['submit'] = array(    $form['import_fieldset']['submit'] = array(
297      '#type' => 'submit',      '#type' => 'submit',
# Line 323  function _ipauth_check_import($row) { Line 328  function _ipauth_check_import($row) {
328  function ipauth_import_export_submit($form_id, &$form_state) {  function ipauth_import_export_submit($form_id, &$form_state) {
329    
330    //define your limits for the submission here    //define your limits for the submission here
331    $limits = array ( 'extensions' => 'cvs' );    $limits = array ( 'extensions' => 'CSV' );
332    
333    $validators = array(    $validators = array(
334      'file_validate_extensions' => array($limits['extensions']),      'file_validate_extensions' => array($limits['extensions']),
# Line 331  function ipauth_import_export_submit($fo Line 336  function ipauth_import_export_submit($fo
336    
337    // Save new file uploads.    // Save new file uploads.
338    if ($file = file_save_upload('import', $validators, file_directory_path())) {    if ($file = file_save_upload('import', $validators, file_directory_path())) {
339      $cvs_file = file($file->filepath);      $CSV_file = file($file->filepath);
340      //id, uid, ip1, ip2, description, enabled, UNIX_TIMESTAMP(created) as created      //id, uid, ip1, ip2, description, enabled, UNIX_TIMESTAMP(created) as created
341      foreach ($cvs_file AS $cvs_file_line) {      foreach ($CSV_file AS $CSV_file_line) {
342        list($row["id"], $row["uid"], $row["ip1"], $row["ip2"], $row["description"], $row["enabled"], $row["created"]) = split(",", $cvs_file_line);        list($row["id"], $row["uid"], $row["ip1"], $row["ip2"], $row["description"], $row["enabled"], $row["created"]) = split(",", $CSV_file_line);
343        array_walk($row, '_ipauth_strip_quotes');        array_walk($row, '_ipauth_strip_quotes');
344        if (_ipauth_check_import($row)) {        if (_ipauth_check_import($row)) {
345          $sql = "INSERT INTO {ip_authenticator} (uid, ip1, ip2, description, enabled, created) VALUES ('%s','%s','%s','%s', '%d', '%s')";          $sql = "INSERT INTO {ip_authenticator} (uid, ip1, ip2, description, enabled, created) VALUES ('%s','%s','%s','%s', '%d', '%s')";
# Line 342  function ipauth_import_export_submit($fo Line 347  function ipauth_import_export_submit($fo
347        }        }
348      }      }
349    
350      drupal_set_message("The CVS file as been successfully imported.");      drupal_set_message("The CSV file as been successfully imported.");
351    
352      //need to remove the file: http://api.drupal.org/api/file/includes/file.inc/6      //need to remove the file: http://api.drupal.org/api/file/includes/file.inc/6
353      file_delete($file->filepath);      file_delete($file->filepath);
# Line 980  function is_ipauth_user($not = FALSE, $a Line 985  function is_ipauth_user($not = FALSE, $a
985  }  }
986    
987  /**  /**
988   * This function will return to the browser a CVS file containing all IP Authenticators.   * This function will return to the browser a CSV file containing all IP Authenticators.
989   * @param <string> $which_ones this is optional and reserved for future use.   * @param <string> $which_ones this is optional and reserved for future use.
990   */   */
991  function ipauth_export($which_ones) {  function ipauth_export($which_ones) {
# Line 989  function ipauth_export($which_ones) { Line 994  function ipauth_export($which_ones) {
994    header("Cache-Control: must-revalidate, post-check=0, pre-check=0");    header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
995    header("Cache-Control: private",false);    header("Cache-Control: private",false);
996    header("Content-Type: application/zip");    header("Content-Type: application/zip");
997    header("Content-Disposition: attachment; filename=IP_Authenticator_Export_".date("Y-m-d").".cvs;" );    header("Content-Disposition: attachment; filename=IP_Authenticator_Export_".date("Y-m-d").".csv;" );
998    $result = ipauth_get_ip_authenticators(NULL, "id, uid, ip1, ip2, description, enabled, UNIX_TIMESTAMP(created) as created");    $result = ipauth_get_ip_authenticators(NULL, "id, uid, ip1, ip2, description, enabled, UNIX_TIMESTAMP(created) as created");
999    while ($row = db_fetch_array($result)) {    while ($row = db_fetch_array($result)) {
1000      printf('"%s","%s","%s","%s","%s","%s","%s"      printf('"%s","%s","%s","%s","%s","%s","%s"

Legend:
Removed from v.1.8  
changed lines
  Added in v.1.9

  ViewVC Help
Powered by ViewVC 1.1.2