[ Index ]
 

Code source de vtiger CRM 5.0.2

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/modules/Import/ -> ImportStep2.php (source)

   1  <?php
   2  /*********************************************************************************
   3   * The contents of this file are subject to the SugarCRM Public License Version 1.1.2
   4   * ("License"); You may not use this file except in compliance with the 
   5   * License. You may obtain a copy of the License at http://www.sugarcrm.com/SPL
   6   * Software distributed under the License is distributed on an  "AS IS"  basis,
   7   * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
   8   * the specific language governing rights and limitations under the License.
   9   * The Original Code is:  SugarCRM Open Source
  10   * The Initial Developer of the Original Code is SugarCRM, Inc.
  11   * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.;
  12   * All Rights Reserved.
  13   * Contributor(s): ______________________________________.
  14   ********************************************************************************/
  15  /*********************************************************************************
  16   * $Header$
  17   * Description:  TODO: To be written.
  18   * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
  19   * All Rights Reserved.
  20   * Contributor(s): ______________________________________..
  21   ********************************************************************************/
  22  
  23  require_once ('Smarty_setup.php');
  24  require_once ('modules/Import/ImportLead.php');
  25  require_once ('modules/Import/ImportAccount.php');
  26  require_once ('modules/Import/ImportContact.php');
  27  require_once ('modules/Import/ImportOpportunity.php');
  28  require_once ('modules/Import/ImportProduct.php');
  29  require_once ('modules/Import/Forms.php');
  30  require_once ('modules/Import/parse_utils.php');
  31  require_once ('modules/Import/ImportMap.php');
  32  require_once ('include/database/PearDatabase.php');
  33  require_once ('include/CustomFieldUtil.php');
  34  require_once ('include/utils/CommonUtils.php');
  35  
  36  @session_unregister('column_position_to_field');
  37  @session_unregister('totalrows');
  38  @session_unregister('recordcount');
  39  @session_unregister('startval');
  40  @session_unregister('return_field_count');
  41  $_SESSION['totalrows'] = '';
  42  $_SESSION['recordcount'] = 500;
  43  $_SESSION['startval'] = 0;
  44  
  45  global $mod_strings;
  46  global $mod_list_strings;
  47  global $app_strings;
  48  global $app_list_strings;
  49  global $current_user;
  50  global $import_file_name;
  51  global $upload_maxsize;
  52  
  53  global $import_dir;
  54  $focus = 0;
  55  $delimiter = ',';
  56  $max_lines = 3;
  57  
  58  $has_header = 0;
  59  
  60  if ( isset($_REQUEST['has_header']))
  61  {
  62      $has_header = 1;
  63  }
  64  
  65  global $theme;
  66  $theme_path="themes/".$theme."/";
  67  $image_path=$theme_path."images/";
  68  require_once ($theme_path.'layout_utils.php');
  69  
  70  if (!is_uploaded_file($_FILES['userfile']['tmp_name']) )
  71  {
  72      show_error_import($mod_strings['LBL_IMPORT_MODULE_ERROR_NO_UPLOAD']);
  73      exit;
  74  }
  75  else if ($_FILES['userfile']['size'] > $upload_maxsize)
  76  {
  77      show_error_import( $mod_strings['LBL_IMPORT_MODULE_ERROR_LARGE_FILE'] . " ". $upload_maxsize. " ". $mod_strings['LBL_IMPORT_MODULE_ERROR_LARGE_FILE_END']);
  78      exit;
  79  }
  80  if( !is_writable( $import_dir ))
  81  {
  82      show_error_import($mod_strings['LBL_IMPORT_MODULE_NO_DIRECTORY'].$import_dir.$mod_strings['LBL_IMPORT_MODULE_NO_DIRECTORY_END']);
  83      exit;
  84  }
  85  
  86  $tmp_file_name = $import_dir. "IMPORT_".$current_user->id;
  87  
  88  move_uploaded_file($_FILES['userfile']['tmp_name'], $tmp_file_name);
  89  
  90  
  91  // Now parse the file and look for errors
  92  $ret_value = 0;
  93  
  94  if ($_REQUEST['source'] == 'act')
  95  {
  96      $ret_value = parse_import_act($tmp_file_name,$delimiter,$max_lines,$has_header);
  97  } 
  98  else
  99  {
 100      $ret_value = parse_import($tmp_file_name,$delimiter,$max_lines,$has_header);
 101  }
 102  
 103  if ($ret_value == -1)
 104  {
 105      show_error_import( $mod_strings['LBL_CANNOT_OPEN'] );
 106      exit;
 107  } 
 108  else if ($ret_value == -2)
 109  {
 110      show_error_import( $mod_strings['LBL_NOT_SAME_NUMBER'] );
 111      exit;
 112  }
 113  else if ( $ret_value == -3 )
 114  {
 115      show_error_import( $mod_strings['LBL_NO_LINES'] );
 116      exit;
 117  }
 118  
 119  
 120  $rows = $ret_value['rows'];
 121  $ret_field_count = $ret_value['field_count'];
 122  
 123  $smarty =  new vtigerCRM_Smarty;
 124  
 125  $smarty->assign("TMP_FILE", $tmp_file_name );
 126  $smarty->assign("SOURCE", $_REQUEST['source'] );
 127  
 128  $smarty->assign("MOD", $mod_strings);
 129  $smarty->assign("APP", $app_strings);
 130  
 131  if(isset($_REQUEST['return_module'])) $smarty->assign("RETURN_MODULE", $_REQUEST['return_module']);
 132  if(isset($_REQUEST['return_action'])) $smarty->assign("RETURN_ACTION", $_REQUEST['return_action']);
 133  
 134  $smarty->assign("THEME", $theme);
 135  $smarty->assign("IMAGE_PATH", $image_path);
 136  $smarty->assign("PRINT_URL", "phprint.php?jt=".session_id().$GLOBALS['request_string']);
 137  
 138  $smarty->assign("HEADER", $app_strings['LBL_IMPORT']." ". $mod_strings['LBL_MODULE_NAME']);
 139  $smarty->assign("HASHEADER", $has_header);
 140  
 141  $import_object_array = Array(
 142                  "Leads"=>"ImportLead",
 143                  "Accounts"=>"ImportAccount",
 144                  "Contacts"=>"ImportContact",
 145                  "Potentials"=>"ImportOpportunity",
 146                  "Products"=>"ImportProduct"
 147                  );
 148  
 149  if(isset($_REQUEST['module']) && $_REQUEST['module'] != '')
 150  {
 151      $object_name = $import_object_array[$_REQUEST['module']];
 152      $focus = new $object_name();
 153  }
 154  else
 155  {
 156      $focus = new ImportContact();
 157  }
 158  
 159  
 160  $total_num_rows=sizeof($rows);    
 161  $firstrow = $rows[0];
 162  if($total_num_rows >1 )
 163  {
 164      $secondrow = $rows[1];
 165  }        
 166  if($total_num_rows >2)
 167  {
 168      $thirdrow = $rows[2];
 169  }
 170  
 171      
 172  $field_map = $outlook_contacts_field_map;
 173  
 174  $mapping_file = new ImportMap();
 175  $saved_map_lists = $mapping_file->getSavedMappingsList($_REQUEST['return_module']);
 176  $map_list_combo = '<select name="source" id="saved_source" disabled onchange="getImportSavedMap(this)">';
 177  $map_list_combo .= '<OPTION value="-1" selected>--Select--</OPTION>';
 178  if(is_array($saved_map_lists))
 179  {
 180      foreach($saved_map_lists as $mapid => $mapname)
 181      {
 182          $map_list_combo .= '<OPTION value='.$mapid.'>'.$mapname.'</OPTION>';
 183      }
 184  }
 185  $map_list_combo .= '</select>';
 186  //This link is Delete link for the selected mapping
 187  $map_list_combo .= "&nbsp;&nbsp;&nbsp;<span id='delete_mapping' style='visibility:hidden;'><a href='javascript:; deleteMapping();'>Del</a></span>";
 188  $smarty->assign("SAVED_MAP_LISTS",$map_list_combo);
 189  
 190  
 191  if ( count($mapping_arr) > 0)
 192  {
 193      $field_map = &$mapping_arr;
 194  }
 195  else if ($_REQUEST['source'] == 'other')
 196  {
 197      if ($_REQUEST['module'] == 'Contacts')
 198      {
 199          $field_map = $outlook_contacts_field_map;
 200      } 
 201      else if ($_REQUEST['module'] == 'Accounts')
 202      {
 203          $field_map = $outlook_accounts_field_map;
 204      }
 205      else if ($_REQUEST['module'] == 'Potentials')
 206      {
 207          $field_map = $salesforce_opportunities_field_map;
 208      }
 209  } 
 210  
 211  
 212  $add_one = 1;
 213  $start_at = 0;
 214  
 215  if($has_header)
 216  {
 217      $add_one = 0;
 218      $start_at = 1;
 219  } 
 220  
 221  for($row_count = $start_at; $row_count < count($rows); $row_count++ )
 222  {
 223      $smarty->assign("ROWCOUNT", $row_count + $add_one);
 224  }
 225  
 226  $list_string_key = strtolower($_REQUEST['module']);
 227  $list_string_key .= "_import_fields";
 228  
 229  $translated_column_fields = $mod_list_strings[$list_string_key];
 230  
 231  // adding custom vtiger_fields translations
 232  getCustomFieldTrans($_REQUEST['module'],&$translated_column_fields);
 233  
 234  $cnt=1;
 235  for($field_count = 0; $field_count < $ret_field_count; $field_count++)
 236  {
 237  
 238      $smarty->assign("COLCOUNT", $field_count + 1);
 239      $suggest = "";
 240  
 241      /*
 242      if ($has_header && isset( $field_map[$firstrow[$field_count]] ) )
 243      {
 244          $suggest = $field_map[$firstrow[$field_count]];    
 245      }
 246      else if (isset($field_map[$field_count]))
 247      {
 248          $suggest = $field_map[$field_count];    
 249      }
 250      */
 251  
 252      if($_REQUEST['module']=='Accounts')
 253      {
 254          $tablename='account';
 255          $focus1=new Accounts();
 256      }
 257      if($_REQUEST['module']=='Contacts')
 258      {
 259          $tablename='contactdetails';
 260          $focus1=new Contacts();
 261       }
 262      if($_REQUEST['module']=='Leads')
 263       {
 264          $tablename='leaddetails';
 265          $focus1=new Leads();
 266      }
 267      if($_REQUEST['module']=='Potentials')
 268       {
 269          $tablename='potential';
 270          $focus1=new Potentials();
 271      }
 272      if($_REQUEST['module']=='Products')
 273       {
 274           $tablename='products';
 275           $focus1=new Products();
 276       }
 277  
 278      
 279      $smarty->assign("FIRSTROW",$firstrow);
 280      $smarty->assign("SECONDROW",$secondrow);
 281      $smarty->assign("THIRDROW",$thirdrow);
 282      $smarty_array[$field_count + 1] = getFieldSelect(    $focus->importable_fields,
 283                              $field_count,
 284                              $focus1->required_fields,
 285                              $suggest,
 286                              $translated_column_fields,
 287                              $tablename
 288                             );
 289  
 290      $pos = 0;
 291  
 292      foreach ( $rows as $row ) 
 293      {
 294          
 295          if( isset($row[$field_count]) && $row[$field_count] != '')
 296          {
 297              $smarty->assign("CELL",htmlspecialchars($row[$field_count]));
 298  //            $smarty->parse("main.table.row.cell");
 299          } 
 300          else
 301          {
 302  //            $smarty->parse("main.table.row.cellempty");
 303          }
 304  
 305          $cnt++;
 306      }
 307  }
 308  @session_unregister('import_has_header');
 309  @session_unregister('import_firstrow');
 310  @session_unregister('import_field_map');
 311  @session_unregister('import_module_object_column_fields');
 312  @session_unregister('import_module_field_count');
 313  @session_unregister('import_module_object_required_fields');
 314  @session_unregister('import_module_translated_column_fields');
 315  $_SESSION['import_has_header'] = $has_header;
 316  $_SESSION['import_firstrow'] = $firstrow;
 317  $_SESSION['import_field_map'] = $field_map;
 318  $_SESSION['import_module_object_column_fields'] = $focus->importable_fields;
 319  $_SESSION['import_module_field_count'] = $field_count;
 320  $_SESSION['import_module_object_required_fields'] = $focus1->required_fields;
 321  $_SESSION['import_module_translated_column_fields'] = $translated_column_fields;
 322  
 323  
 324  //echo '<pre>Default array ==> '; print_r($smarty_array); echo '</pre>';
 325  
 326  $smarty->assign("SELECTFIELD",$smarty_array);
 327  $smarty->assign("ROW", $row);
 328  
 329  $module_key = "LBL_".strtoupper($_REQUEST['module'])."_NOTE_";
 330  
 331  for ($i = 1;isset($mod_strings[$module_key.$i]);$i++)
 332  {
 333      $smarty->assign("NOTETEXT", $mod_strings[$module_key.$i]);
 334  }
 335  
 336  if($has_header)
 337  {
 338      $smarty->assign("HAS_HEADER", 'on');
 339  } 
 340  else
 341  {
 342      $smarty->assign("HAS_HEADER", 'off');
 343  }
 344  
 345  $smarty->assign("MODULE", $_REQUEST['module']);
 346  $smarty->assign('CATEGORY' , $_REQUEST['parenttab']);
 347  @$_SESSION['import_parenttab'] = $_REQUEST['parenttab'];
 348  $smarty->assign("JAVASCRIPT2", get_readonly_js() );
 349  
 350  $smarty->display('ImportStep2.tpl');
 351  
 352  ?>
 353  <script language="javascript" type="text/javascript">
 354  function validate_import_map()
 355  {
 356      var tagName;
 357      var count = 0;
 358      var field_count = "<?php echo $field_count; ?>";
 359      var required_fields = new Array();
 360      var required_fields_name = new Array();
 361      var seq_string = '';
 362  
 363      <?php 
 364          foreach($focus->required_fields as $name => $index)
 365          {
 366              ?>
 367              required_fields[count] = "<?php echo $name; ?>";
 368              required_fields_name[count] = "<?php echo $translated_column_fields[$name]; ?>";
 369              count = count + 1;
 370              <?php 
 371          } 
 372      ?>        
 373      for(loop_count = 0; loop_count<field_count;loop_count++)
 374      {
 375          tagName = document.getElementById('colnum'+loop_count);
 376          optionData = tagName.options[tagName.selectedIndex].value;
 377  
 378          if(optionData != -1)
 379          {
 380              tmp = seq_string.indexOf("\""+optionData+"\"");
 381              if(tmp == -1)
 382              {
 383                  seq_string = seq_string + "\""+optionData+"\"";
 384              }
 385              else
 386              {
 387                  //if a vtiger_field mapped more than once, alert the user and return
 388                  alert("'"+tagName.options[tagName.selectedIndex].text+"' is mapped more than once. Please check the mapping.");
 389                  return false;
 390              }
 391          }
 392  
 393      }
 394  
 395      //check whether the mandatory vtiger_fields have been mapped.
 396      for(inner_loop = 0; inner_loop<required_fields.length;inner_loop++)
 397      {
 398          if(seq_string.indexOf(required_fields[inner_loop]) == -1)
 399          {
 400              alert('Please map the mandatory field "'+required_fields_name[inner_loop]+'"');
 401              return false;
 402          }
 403      }
 404  
 405      //This is to check whether the save map name has been given or not when save map check box is checked
 406      if(document.getElementById("save_map").checked == true)
 407      {
 408          if(trim(document.getElementById("save_map_as").value) == '')
 409          {
 410              alert("Please Enter Save Map Name");
 411              return false;
 412          }
 413      }
 414  
 415      return true;
 416  }
 417  </script>


Généré le : Sun Feb 25 10:22:19 2007 par Balluche grâce à PHPXref 0.7