/[drupal]/contributions/modules/sin/sin.module
ViewVC logotype

Diff of /contributions/modules/sin/sin.module

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

revision 1.2, Sun May 6 13:33:00 2007 UTC revision 1.3, Mon Dec 1 00:43:18 2008 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: phone.module,v 1.02 2006/10/01 21:47:01 thierry_gd Exp $  // $Id: sin.module,v 1.02 2008/11/16 21:47:01 thierry_gd Exp $
3    
4  // Copyright 2006 Thierry GUEGAN http://www.arvoriad.com  // Copyright 2008 Thierry GUEGAN http://www.arvoriad.com
5    
6  /**  /**
7   * @file   * @file
# Line 9  Line 9 
9   * Provide some verifications on the social insurance numbers   * Provide some verifications on the social insurance numbers
10   */   */
11    
12    
13    /**
14     * @addtogroup install
15     * @{
16     */
17    /**
18     * Implementation of hook_content_notify().
19     *
20     * This hook should be implemented inside hook_install(), hook_uninstall(),
21     * hook_enable() and hook_disable(), and is used to notify the content
22     * module when a field module is added or removed so it can respond
23     * appropriately. One use of this hook is to allow the content module
24     * to remove fields and field data created by this module when the
25     * module is uninstalled.
26     *
27     * The recommended location for these hooks is in the module's .install file.
28     */
29    /**
30     * Implementation of hook_install().
31     */
32    function sin_install() {
33      content_notify('install', 'sin');
34    }
35    
36    /**
37     * Implementation of hook_uninstall().
38     */
39    function sin_uninstall() {
40      content_notify('uninstall', 'sin');
41    }
42    
43    /**
44     * Implementation of hook_enable().
45     *
46     * Notify content module when this module is enabled.
47     */
48    function sin_enable() {
49      content_notify('enable', 'sin');
50    }
51    
52    /**
53     * Implementation of hook_disable().
54     *
55     * Notify content module when this module is disabled.
56     */
57    function sin_disable() {
58      content_notify('disable', 'sin');
59    }
60    /**
61     * @} End of "addtogroup install".
62     */
63    
64    
65  /**  /**
66   * Implementation of hook_field_info().   * Implementation of hook_field_info().
67     * Implementation of hook_field_info().
68     *
69     * Here we indicate that the content module will use its default
70     * handling for the view of this field.
71     *
72     * Callbacks can be omitted if default handing is used.
73     * They're included here just so this module can be used
74     * as an example for custom modules that might do things
75     * differently.
76     *
77     * If your module will provide its own Views tables or arguments,
78     * change CONTENT_CALLBACK_DEFAULT to CONTENT_CALLBACK_CUSTOM.
79     *
80     * IMPORTANT! - field and widget names will be truncated to 32 characters in
81     * the database and in internal arrays, like content_fields().
82   */   */
83  function sin_field_info() {  function sin_field_info() {
84    return array(    return array(
# Line 20  function sin_field_info() { Line 88  function sin_field_info() {
88     );     );
89  }  }
90    
91    /**
92     * Implementation of hook_theme().
93     */
94    function sin_theme() {
95      return array(
96        'sin_textfield' => array(
97          'arguments' => array('element' => NULL),
98        ),
99        'sin_formatter_default' => array(
100          'arguments' => array('element' => NULL),
101        ),
102      );
103    }
104    
105  /**  /**
106   * Implementation of hook_field_settings().   * Implementation of hook_field_settings().
107     *
108     * Handle the settings for a field.
109     *
110     * @param $op
111     *   The operation to be performed. Possible values:
112     *   - "form": Display the field settings form.
113     *   - "validate": Check the field settings form for errors.
114     *   - "save": Declare which fields to save back to the database.
115     *   - "database columns": Declare the columns that content.module should create
116     *     and manage on behalf of the field. If the field module wishes to handle
117     *     its own database storage, this should be omitted.
118     *   - "filters": Declare the Views filters available for the field.
119     *     (this is used in CCK's default Views tables definition)
120     *     They always apply to the first column listed in the "database columns"
121     *     array.
122     * @param $field
123     *   The field on which the operation is to be performed.
124     * @return
125     *   This varies depending on the operation.
126     *   - "form": an array of form elements to add to
127     *     the settings page.
128     *   - "validate": no return value. Use form_set_error().
129     *   - "save": an array of names of form elements to
130     *     be saved in the database.
131     *   - "database columns": an array keyed by column name, with arrays of column
132     *     information as values. This column information must include "type", the
133     *     MySQL data type of the column, and may also include a "sortable" parameter
134     *     to indicate to views.module that the column contains ordered information.
135     *     TODO: Details of other information that can be passed to the database layer can
136     *     be found in the API for the Schema API.
137     *   - "filters": an array of 'filters' definitions as expected by views.module
138     *     (see Views Documentation).
139     *     When providing several filters, it is recommended to use the 'name'
140     *     attribute in order to let the user distinguish between them. If no 'name'
141     *     is specified for a filter, the key of the filter will be used instead.
142   */   */
143  function sin_field_settings($op, $field) {  function sin_field_settings($op, $field) {
144    switch ($op) {    switch ($op) {
# Line 48  function sin_field_settings($op, $field) Line 164  function sin_field_settings($op, $field)
164    
165  /**  /**
166   * Implementation of hook_field().   * Implementation of hook_field().
167     *
168     * Define the behavior of a field type.
169     *
170     * @param $op
171     *   What kind of action is being performed. Possible values:
172     *   - "load": The node is about to be loaded from the database. This hook
173     *     should be used to load the field.
174     *   - "validate": The user has just finished editing the node and is
175     *     trying to preview or submit it. This hook can be used to check or
176     *     even modify the node. Errors should be set with form_set_error().
177     *   - "presave": The user has just finished editing the node and the node has
178     *     passed validation. This hook can be used to modify the node.
179     *   - "insert": The node is being created (inserted in the database).
180     *   - "update": The node is being updated.
181     *   - "delete": The node is being deleted.
182     * @param &$node
183     *   The node the action is being performed on. This argument is passed by
184     *   reference for performance only; do not modify it.
185     * @param $field
186     *   The field the action is being performed on.
187     * @param &$node_field
188     *   The contents of the field in this node. Changes to this variable will
189     *   be saved back to the node object.
190     * @return
191     *   This varies depending on the operation.
192     *   - The "load" operation should return an object containing extra values
193     *     to be merged into the node object.
194     *   - The "insert", "update", "delete", "validate", and "presave" operations
195     *     have no return value.
196     *
197     * In most cases, only "validate" operations is relevant ; the rest
198     * have default implementations in content_field() that usually suffice.
199   */   */
200  function sin_field($op, &$node, $field, &$node_field, $teaser, $page) {  function sin_field($op, &$node, $field, &$node_field, $teaser, $page) {
201    switch ($op) {    switch ($op) {
202      case 'view':      case 'validate': // corresponds to hook phone_widget validate in sin-5.x
203        foreach ($node_field as $delta => $item) {        foreach ($node_field as $delta => $item) {
204          //$node_field[$delta]['view'] = sin_field_view_item($field, $item);          if ($item['value'] != '') {
205          $node_field[$delta]['view'] = content_format($field, $item, 'default', $node);            if ($field['type'] == 'fr_sin' && !valid_fr_sin($item['value'])) {
206                form_set_error($field['field_name'],t('"%value" is not a valid French Social Insurance Numbers<br>Social Insurance Numbers should only contains numbers and be like ...',array('%value' => $item['value'])));
207              }
208              if ($field['type'] == 'ca_sin' && !valid_ca_sin($item['value'])) {
209                form_set_error($field['field_name'],t('"%value" is not a valid Canadian Social Insurance Numbers<br>Social Insurance Numbers should be like 999999999 ...',array('%value' => $item['value'])));
210              }
211              if ($field['type'] == 'us_sin' && !valid_us_sin($item['value'])) {
212                form_set_error($field['field_name'],t('"%value" is not a valid US Social Insurance Numbers<br>Social Insurance Numbers should be like 999-99-9999 or 999999999 ...',array('%value' => $item['value'])));
213              }
214            }
215          }
216          break;
217    
218        case 'presave': // corresponds to hook phone_widget 'process form values' in sin-5.x
219          foreach ($node_field as $delta => $item) {
220            //format the phone number
221            if ($item['value'] != '') {
222              if ($field['type'] == 'fr_sin') {
223                $node_field[$delta]['value'] = format_sin_number('fr', $node_field[$delta]['value'], $field);
224              }
225              if ($field['type'] == 'ca_sin') {
226                $node_field[$delta]['value'] = format_sin_number('ca', $node_field[$delta]['value'], $field);
227              }
228              if ($field['type'] == 'us_sin') {
229                $node_field[$delta]['value'] = format_sin_number('us', $node_field[$delta]['value'], $field);
230              }
231            }
232        }        }
233        return theme('field', $node, $field, $node_field, $teaser, $page);        break;
234    }    }
235  }  }
236    
# Line 72  function sin_field_view_item($field, $no Line 246  function sin_field_view_item($field, $no
246  */  */
247    
248  /**  /**
249   *Implementation of hook_field_formatter_info   *Implementation of hook_field_formatter_info().
250     * Implementation of hook_field_formatter_info().
251     *
252     * The default behavior of formatters is that they will create
253     * a theme for a single field value.
254     *
255     * Setting 'multiple values' to CONTENT_HANDLE_FIELD will create
256     * a formatter that will receive all the values of a field so you
257     * can, for instance, plot all the values on a map or in a graph.
258     *
259     * The 'view' operation (handled by the Content module) constructs the
260     * $node in a way that you can use drupal_render() to display the
261     * formatted output for an individual field.
262     *
263     * i.e. print drupal_render($node->field_foo);
264     *
265     * The code now supports both single value formatters, which theme an
266     * individual item value as has been done in previous version of CCK,
267     * and multiple value formatters, which theme all values for the field
268     * in a single theme. The multiple value formatters could be used, for
269     * instance, to plot field values on a single map or display them
270     * in a graph. Single value formatters are the default, multiple value
271     * formatters can be designated as such in formatter_info().
272     *
273     * The node array will look like:
274   *   *
275     *  'Single value' formatter:
276     *   $node->content['field_foo'] = array(
277     *     '#type' => 'content_field',
278     *     '#title' => 'label'
279     *     '#field_name' => 'field_name',
280     *     '#node' => $node,
281     *     'items' =>
282     *       0 => array(
283     *         '#theme' => $theme,
284     *         '#field_name' => 'field_name',
285     *         '#type_name' => $node->type,
286     *         '#formatter' => $formatter_name,
287     *         '#item' => $items[0],
288     *       ),
289     *       1 => array(
290     *         '#theme' => $theme,
291     *         '#field_name' => 'field_name',
292     *         '#type_name' => $node->type,
293     *         '#formatter' => $formatter_name,
294     *         '#item' => $items[1],
295     *       ),
296     *     ),
297     *   );
298     *  'Multiple value' formatter:
299     *   $node->content['field_foo'] = array(
300     *     '#type' => 'content_field',
301     *     '#title' => 'label'
302     *     '#field_name' => 'field_name',
303     *     '#node' => $node,
304     *     'items' => array(
305     *       '#theme' => $theme,
306     *       '#field_name' => 'field_name',
307     *       '#type_name' => $node->type,
308     *       '#formatter' => $formatter_name,
309     *       0 => array(
310     *         '#item' => $items[0],
311     *       ),
312     *       1 => array(
313     *         '#item' => $items[1],
314     *       ),
315     *     ),
316     *   );
317   */   */
318  function sin_field_formatter_info() {  function sin_field_formatter_info() {
319    return array(    return array(
320      'default' => array(      'default' => array(
321        'label' => 'Default',        'label' => 'Default',
322        'field types' => array('fr_sin', 'ca_sin', 'us_sin'),        'field types' => array('fr_sin',
323                            'ca_sin',
324                            'us_sin'
325                            ),
326          'multiple values' => CONTENT_HANDLE_CORE,
327      ),      ),
328    );    );
329   }   }
330    
331  /**  /**
332    *Implementation of hook_field_formatter   *Implementation of hook_field_formatter().
333    */   *
334     * Prepare an individual item for viewing in a browser.
335     *
336     * @param $field
337     *   The field the action is being performed on.
338     * @param $item
339     *   An array, keyed by column, of the data stored for this item in this field.
340     * @param $formatter
341     *   The name of the formatter being used to display the field.
342     * @param $node
343     *   The node object, for context. Will be NULL in some cases.
344     *   Warning: when displaying field retrieved by Views, $node will not
345     *   be a "full-fledged" node object, but an object containg the data returned
346     *   by the Views query (at least nid, vid, changed)
347     * @return
348     *   An HTML string containing the formatted item.
349     *
350     * In a multiple-value field scenario, this function will be called once per
351     * value currently stored in the field. This function is also used as the handler
352     * for viewing a field in a views.module tabular listing.
353     *
354     * It is important that this function at the minimum perform security
355     * transformations such as running check_plain() or check_markup().
356     */
357  function sin_field_formatter($field, $item, $formatter, $node) {  function sin_field_formatter($field, $item, $formatter, $node) {
358    if (!isset($item['value'])) {    if (!isset($item['value'])) {
359      return '';      return '';
# Line 102  function sin_field_formatter($field, $it Line 369  function sin_field_formatter($field, $it
369    
370  /**  /**
371   * Implementation of hook_widget_info().   * Implementation of hook_widget_info().
372     *
373     * Here we indicate that the content module will handle
374     * the default value and multiple values for these widgets.
375     *
376     * Callbacks can be omitted if default handing is used.
377     * They're included here just so this module can be used
378     * as an example for custom modules that might do things
379     * differently.
380     *
381     * IMPORTANT! - field and widget names will be truncated to 32 characters in
382     * the database and in internal arrays, like content_fields().
383   */   */
384  function sin_widget_info() {  function sin_widget_info() {
385    return array(    return array(
386      'sin' => array(      'sin_textfield' => array(
387        'label' => t('Textfield'),        'label' => t('Textfield'),
388        'field types' => array('fr_sin', 'ca_sin', 'us_sin'),        'field types' => array('fr_sin',
389                            'ca_sin',
390                            'us_sin'
391                            ),
392          'multiple values' => CONTENT_HANDLE_CORE,
393          'callbacks' => array(
394            'default value' => CONTENT_CALLBACK_DEFAULT,
395          ),
396      ),      ),
397    );    );
398  }  }
399    
400  /**  /**
401   * Implementation of hook_widget_settings().   * Implementation of hook_widget_settings().
402     *
403     * Handle the parameters for a widget.
404     *
405     * @param $op
406     *   The operation to be performed. Possible values:
407     *   - "form": Display the widget settings form.
408     *   - "validate": Check the widget settings form for errors.
409     *   - "save": Declare which pieces of information to save back to the database.
410     * @param $widget
411     *   The widget on which the operation is to be performed.
412     * @return
413     *   This varies depending on the operation.
414     *   - "form": an array of form elements to add to the settings page.
415     *   - "validate": no return value. Use form_set_error().
416     *   - "save": an array of names of form elements to be saved in the database.
417   */   */
418  function sin_widget_settings($op, $widget) {  function sin_widget_settings($op, $widget) {
419    switch ($op) {    switch ($op) {
# Line 129  function sin_widget_settings($op, $widge Line 429  function sin_widget_settings($op, $widge
429    
430  /**  /**
431   * Implementation of hook_widget().   * Implementation of hook_widget().
432     *
433     * Attach a single form element to the form. It will be built out and
434     * validated in the callback(s) listed in hook_elements. We build it
435     * out in the callbacks rather than here in hook_widget so it can be
436     * plugged into any module that can provide it with valid
437     * $field information.
438     *
439     * Content module will set the weight, field name and delta values
440     * for each form element. This is a change from earlier CCK versions
441     * where the widget managed its own multiple values.
442     *
443     * If there are multiple values for this field, the content module will
444     * call this function as many times as needed.
445     *
446     * @param $form
447     *   the entire form array, $form['#node'] holds node information
448     * @param $form_state
449     *   the form_state, $form_state['values'][$field['field_name']]
450     *   holds the field's form values.
451     * @param $field
452     *   the field array
453     * @param $items
454     *   array of default values for this field
455     * @param $delta
456     *   the order of this item in the array of subelements (0, 1, 2, etc)
457     *
458     * @return
459     *   the form item for a single element for this field
460   */   */
461  function sin_widget($op, &$node, $field, &$node_field) {  function sin_widget(&$form, &$form_state, $field, $items, $delta = 0) {
462    switch ($op) {    $element = array(
463      case 'form':      '#type' => $field['widget']['type'],
464        $form = array();      '#default_value' => isset($items[$delta]) ? $items[$delta] : NULL,
465        $form[$field['field_name']] = array('#tree' => TRUE);    );
466      return $element;
       if ($field['multiple']) {  
         $form[$field['field_name']]['#type'] = 'fieldset';  
         $form[$field['field_name']]['#title'] = t($field['widget']['label']);  
         foreach (range(0,2) as $delta) {  
           $form[$field['field_name']][$delta]['value'] = array(  
             '#type' => 'textfield',  
             '#title' => '',  
             '#default_value' => isset($node_field[$delta]['value']) ? $node_field[$delta]['value'] : '',  
             '#required' => $field['required'] ? $field['required'] : FALSE,  
             '#maxlength' => 255,  
             '#weight' => $field['widget']['weight'],  
             '#size' => isset($field['widget']['size']) ? $field['widget']['size'] : 20,  
           );  
         }  
       }  
       else {  
         $form[$field['field_name']][0]['value'] = array(  
           '#type' => 'textfield',  
           '#title' => $field['widget']['label'],  
           '#default_value' => isset($node_field[0]['value']) ? $node_field[0]['value'] : '',  
           '#required' => $field['required'] ? $field['required'] : FALSE,  
           '#maxlength' => 255,  
           '#weight' => $field['widget']['weight'],  
           '#size' => isset($field['widget']['size']) ? $field['widget']['size'] : 20,  
         );  
       }  
   
       return $form;  
   
     case 'process form values':  
           if (is_array($node_field)) {  
             foreach ($node_field as $delta => $item) {  
             //format the sin  
               if ($item['value'] != '')  
               {  
                 if ($field['type'] == 'fr_sin') {  
                   $node_field[0]['value'] = format_fr_sin($node_field[0]['value']);  
                 }  
                 if ($field['type'] == 'ca_sin') {  
                   $node_field[0]['value'] = format_ca_sin($node_field[0]['value']);  
                 }  
                 if ($field['type'] == 'us_sin') {  
                   $node_field[0]['value'] = format_us_sin($node_field[0]['value']);  
                 }  
               }  
             }  
           }  
     break;  
   
     case 'validate':  
       if (is_array($node_field)) {  
           foreach ($node_field as $delta => $item) {  
   
             if ($item['value'] != '')  
             {  
               if ($field['type'] == 'fr_sin' && !valid_fr_sin($item['value'])) {  
                 form_set_error($field['field_name'],t('"%value" is not a valid french Social Insurance Numbers<br>Social Insurance Numbers should only contains numbers and be like ...',array('%value' => $item['value'])));  
               }  
               if ($field['type'] == 'ca_sin' && !valid_ca_sin($item['value'])) {  
                 form_set_error($field['field_name'],t('"%value" is not a canadian valid Social Insurance Numbers<br>Social Insurance Numbers should be like 999999999 ...',array('%value' => $item['value'])));  
               }  
               if ($field['type'] == 'us_sin' && !valid_us_sin($item['value'])) {  
                 form_set_error($field['field_name'],t('"%value" is not a valid us Social Insurance Numbers<br>Social Insurance Numbers should be like 999-99-9999 or 999999999 ...',array('%value' => $item['value'])));  
               }  
             }  
           }  
       }  
       break;  
   }  
467  }  }
468    
469  /**  /**
470   * Verification for Social Insurance Numbers.   * Implementation of hook_content_is_empty().
471   *   *
472   * @param string $text   * NEW REQUIRED HOOK!
473   * @return boolean Returns boolean FALSE if the Social Insurance Numbers is not valid.   *
474   * On success, returns a string containting the Social Insurance Numbers with some formatting.   * This function tells the content module whether or not to consider
475     * the $item to be empty. This is used by the content module
476     * to remove empty, non-required values before saving them.
477   */   */
478  function valid_fr_sin($sinstring) {  function sin_content_is_empty($item, $field) {
479      return FALSE;
480    $sinstring = trim($sinstring);  }
481    
482    if (!preg_match("/^(1|2)[ ]{0,1}\d{2}[ ]{0,1}\d{2}[ ]{0,1}\d{2}[ ]\d{3}[ ]{0,1}\d{3}[ ]{0,1}\d{2}$/i",$sinstring)) {  /**
483          return false;   * Implementation of FAPI hook_elements().
484    }   *
485    //1 72 06 28 151 045 34   * Any FAPI callbacks needed for individual widgets can be declared here,
486    else   * and the element will be passed to those callbacks for processing.
487    {   *
488          return true;   * Drupal will automatically theme the element using a theme with
489    }   * the same name as the hook_elements key.
490  }   *
491     * Autocomplete_path is not used by text_widget but other widgets can use it
492     * (see nodereference and userreference).
493     */
494     function sin_elements() {
495      return array(
496        'sin_textfield' => array(
497          '#input' => TRUE,
498          '#columns' => array('value'), '#delta' => 0,
499          '#process' => array('sin_textfield_process'),
500          '#autocomplete_path' => FALSE,
501          ),
502      );
503    }
504    
505  function valid_ca_sin($sinstring) {  /**
506     * FAPI theme for an individual text elements.
507     *
508     * The textfield or textarea is already rendered by the
509     * textfield or textarea themes and the html output
510     * lives in $element['#children']. Override this theme to
511     * make custom changes to the output.
512     *
513     * $element['#field_name'] contains the field name
514     * $element['#delta]  is the position of this element in the group
515     */
516    function theme_sin_textfield($element) {
517      return $element['#children'];
518    }
519    
520    $sinstring = trim($sinstring);  /**
521     * Process an individual element.
522     *
523     * Build the form element. When creating a form using FAPI #process,
524     * note that $element['#value'] is already set.
525     *
526     * The $fields array is in $form['#field_info'][$element['#field_name']].
527     */
528    function sin_textfield_process($element, $edit, $form_state, $form) {
529      $field = $form['#field_info'][$element['#field_name']];
530      $field_key = $element['#columns'][0];
531      $delta = $element['#delta'];
532      $element[$field_key] = array(
533        '#type' => 'textfield',
534        '#default_value' => isset($element['#value'][$field_key]) ? $element['#value'][$field_key] : NULL,
535        '#autocomplete_path' => FALSE,
536        // The following values were set by the content module and need
537        // to be passed down to the nested element.
538        '#title' => $element['#title'],
539        '#description' => $element['#description'],
540        '#required' => $element['#required'],
541        '#field_name' => $element['#field_name'],
542        '#type_name' => $element['#type_name'],
543        '#delta' => $element['#delta'],
544        '#columns' => $element['#columns'],
545      );
546    
547    if (!preg_match("/^\d{9}$/i",$sinstring)) {    if (!empty($field['max_length'])) {
548          return false;      $element[$field_key]['#maxlength'] = $field['max_length'];
549    }    }
550    //999999999    if (!empty($field['text_processing'])) {
551    else      $filter_key = $element['#columns'][1];
552    {      $format = isset($element['#value'][$filter_key]) ? $element['#value'][$filter_key] : FILTER_FORMAT_DEFAULT;
553          return true;      $parents = array_merge($element['#parents'] , array($filter_key));
554        $element[$filter_key] = filter_form($format, 1, $parents);
555    }    }
 }  
556    
557  function valid_us_sin($sinstring) {    // Used so that hook_field('validate') knows where to flag an error.
558      $element['_error_element'] = array(
559        '#type' => 'value',
560        '#value' => implode('][', array_merge($element['#parents'], array($field_key))),
561      );
562    
563    $sinstring = trim($sinstring);    return $element;
564    }
565    
   if (!preg_match("/^\d{3}\-?\d{2}\-?\d{4}$/i",$sinstring)) {  
         return false;  
   }  
   //999-99-9999 or999999999  
   else  
   {  
         return true;  
   }  
 }  
   
566  /**  /**
567   * Formatting for Social Insurance Numbers.   * Theme function for 'default' text field formatter.
  *  
  * @param string $sinstring  
  * @return string Returns a string containting the Social Insurance Number with some formatting.  
568   */   */
569  function format_fr_sin($sinstring) {  function theme_sin_formatter_default($element) {
570      return $element['#item']['value'];
   $sinstring = trim($sinstring);  
   //do some formatting  
   return $sinstring;  
571  }  }
572    
573    
574  function format_ca_sin($sinstring) {  /**
575     * Verification for SIN Numbers.
576    $sinstring = trim($sinstring);   *
577    //do some formatting   * @param string $countrycode
578    return $sinstring;   * @param string $sinnumber
579  }   * @return boolean Returns boolean FALSE if the SIN number is not valid.
580     */
581    function valid_sin_number($countrycode, $phonenumber) {
582    
583      $countrycode = trim($countrycode);
584      $sinnumber = trim($sinnumber);
585    
586      if ($countrycode == 'fr'
587            || $countrycode == 'it'
588            || $countrycode == 'ca'
589            || $countrycode == 'cr'
590            || $countrycode == 'uk'
591            || $countrycode == 'ru'
592            || $countrycode == 'es'
593            || $countrycode == 'au'
594            || $countrycode == 'cs'
595            || $countrycode == 'hu'
596            ) {
597    
598            //drupal_set_message('langue = ' . $countrycode, 'error');
599    
600  function format_us_sin($sinstring) {          $valid_sin_function = 'valid_'. $countrycode . '_sin_number';
601            module_load_include('inc', 'sin', './'. drupal_get_path('module', 'sin') . '/sin.'. $countrycode);
602    
603            if (function_exists($valid_sin_function)) {
604                return $valid_phone_function($sinnumber);
605            }
606            else  {
607                return false;
608            }
609      }
610      else {
611            //Country not taken into account yet
612            return false;
613      }
614    }
615    
616    $sinstring = trim($sinstring);  /**
617    //do some formatting   * Verification for SIN Numbers.
618    return $sinstring;   *
619  }   * @param string $countrycode
620     * @param string $sinnumber
621     * @return boolean Returns boolean FALSE if the SIN number is not valid.
622     */
623    function format_sin_number($countrycode, $sinnumber, $field) {
624    
625      $countrycode = trim($countrycode);
626      $sinnumber = trim($sinnumber);
627    
628      if ($countrycode == 'fr'
629            || $countrycode == 'it'
630            || $countrycode == 'ca'
631            || $countrycode == 'cr'
632            || $countrycode == 'uk'
633            || $countrycode == 'ru'
634            || $countrycode == 'es'
635            || $countrycode == 'au'
636            || $countrycode == 'cs'
637            || $countrycode == 'hu'
638            ) {
639    
640            //drupal_set_message('langue = ' . $countrycode, 'error');
641    
642            $format_sin_function = 'format_'. $countrycode . '_sin_number';
643            module_load_include('inc', 'sin', './'. drupal_get_path('module', 'sin') . '/sin.'. $countrycode);
644    
645            if (function_exists($format_sin_function)) {
646                return $format_sin_function($sinnumber, $field);
647            }
648            else {
649                return false;
650            }
651      }
652      else {
653            //Country not taken into account yet
654            return false;
655      }
656    }

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.3

  ViewVC Help
Powered by ViewVC 1.1.2