The progress bar of the import function is ongoing, and the import function cannot be implemented.

Source: Internet
Author: User
The progress bar of the import function is ongoing, and the import function cannot implement upload excel

 SetOutputEncoding ('utf-8'); if ($ _ GET ['file'] = 'user ') {$ filename = $ _ FILES ['myfile'] ['tmp _ name']; $ data-> read ($ filename);/** user import sequence: organization ID, logon name, password, name, phone number, remarks */for ($ I = 1; $ I <= $ data-> sheets [0] ['numrows ']; $ I ++) {for ($ j = 1; $ j <= $ data-> sheets [0] ['numcols']; $ j ++) {// Determine whether the database has a user $ username = trim ($ data-> sheets [0] ['cells '] [$ I] [2]); $ repeatsql = "select username from user where username = '$ username'"; if ($ db-> getNum ($ repeatsql) break; // Determine whether the specified phone number already exists in the database $ phone = trim ($ data-> sheets [0] ['cells '] [$ I] [5]); $ repeatsql = "select username from user where username = '$ username'"; if ($ db-> getNum ($ repeatsql) break; // get the unit id through unit encoding $ code = $ data-> sheets [0] ['cells '] [$ I] [1]; $ deptsql = "select id from dept where code = '$ code'"; dolog ('myfile upload success'); dolog ($ deptsql ); // fwrite (fopen ("/tmp/upload. SQL ", 'AB +'), $ deptsql. "\ r \ n"); $ rs = $ db-> getRow ($ deptsql) or die ("{failure: true, msg :'
 
  
The user's unit code '". $ code."' does not exist. Please verify
 '} "); $ Deptid = $ rs ['id']; // password and name $ password = md5 (trim ($ data-> sheets [0] ['cells '] [$ I] [3]); $ name = trim ($ data-> sheets [0] ['cells '] [$ I] [4]); $ note = trim ($ data-> sheets [0] ['cells '] [$ I] [6]); $ SQL = "INSERT INTO user (dept_id, username, password, name, phone, note) VALUES ('$ demotid',' $ username', '$ password',' $ name', '$ phone',' $ note ') "; dolog ($ SQL); // fwrite (fopen ("/tmp/upload. SQL ", 'AB +'), $ SQL. "\ r \ n"); $ res = $ Db-> query ($ SQL); if (! $ Res) die ("{failure: true, msg: 'The record does not meet the conditions. database error! '} ") ;}} Die (' {success: true, file :'. json_encode ($ filename ). '}');} if ($ _ GET ['file'] = 'dept ') {$ deptfile = $ _ FILES ['dept'] ['tmp _ name']; $ data-> read ($ deptfile);/** unit import sequence: unit code, upper-level unit code, unit name, remarks */for ($ I = 1; $ I <= $ data-> sheets [0] ['numrows ']; $ I ++) {for ($ j = 1; $ j <= $ data-> sheets [0] ['numcols']; $ j ++) {$ code = $ data-> sheets [0] ['cells '] [$ I] [1]; $ parentcode = $ data-> sheets [0] ['cells '] [$ I] [2]; $ parent = "select id from dept where code = '$ parentcode'"; $ parentrs = $ db-> getRow ($ parent) or die ("{failure: true, msg:'
 
  
An error occurred while selecting the parent unit id.
 '} "); $ Deptid = $ parentrs ['id']; $ name = $ data-> sheets [0] ['cells'] [$ I] [3]; // $ restriction = $ data-> sheets [0] ['cells] [$ I] [4]; $ note = $ data-> sheets [0] ['cells '] [$ I] [4]; $ checkcode = "select * from dept where code = '$ code'"; if ($ db-> getNum ($ checkcode) break; $ childsql = "select fn_get_or_create_dept ('$ code',' $ deptid ') as id"; $ result = $ db-> getRow ($ childsql ); $ deptid = $ result ['id']; $ SQL = "update dept set name = '$ name', note =' $ note' where id = $ deptid "; $ db-> query ($ SQL) or die ("{failure: true, msg :'
 
  
An error occurred while adding the unit.
 '} ") ;}} Die (' {success: true, msg :'. json_encode ($ deptfile ). '}');} if ($ _ GET ['file'] = 'ch ') {$ epfile = $ _ FILES ['myfile'] ['tmp _ name']; $ data-> read ($ epfile); // print_r ($ data ); for ($ I = 1; $ I <= $ data-> sheets [0] ['numrows ']; $ I ++) {$ devid = $ data-> sheets [0] ['cells '] [$ I] [1]; $ row = $ ep-> Hasdevid ($ devid ); if ($ row) {$ SQL = "select id from ep where devid = '". $ devid. "'"; $ devtype2 = $ db-> getRow ($ SQL); $ ep_id = $ de Vtype2 ['id']; $ SQL = "insert into dept_has_ep values ('', 167, $ ep_id) "; $ db-> insert ($ SQL );}}} if ($ _ GET ['file'] = 'EP') {$ epfile = $ _ FILES ['myfile'] ['tmp _ name']; $ data-> read ($ epfile);/** device import sequence: organization name, terminal number, terminal name, terminal type, base station positioning, device number, device type, phone number, remarks */dolog ('numrows :'. $ data-> sheets [0] ['numrows ']. "--"); for ($ I = 1; $ I <= $ data-> sheets [0] ['numrows ']; $ I ++) {dolog ('-- I :'. $ I. "--"); $ deptname = $ data-> sheets [0] ['cells] [$ I] [1]; $ Epid = $ data-> sheets [0] ['cells '] [$ I] [2]; $ epname = $ data-> sheets [0] ['cells '] [$ I] [3]; $ eptype = $ data-> sheets [0] ['cells '] [$ I] [4]; $ bsl = $ data-> sheets [0] ['cells '] [$ I] [5]; $ devid = $ data-> sheets [0] ['cells '] [$ I] [6]; $ devtype = $ data-> sheets [0] ['cells '] [$ I] [7]; // $ phone = $ data-> sheets [0] ['cells '] [$ I] [8]; $ info = $ data-> sheets [0] ['cells '] [$ I] [9]; $ row = $ ep-> Hasepid ($ epid ); if ($ row> 0) {dolog ('WARN: epid has Existed '. $ epid); continue; // die ("{failure: true, msg: 'Terminal number repetition '}");} $ row1 = $ ep-> Hasdevid ($ devid); if ($ row1> 0) {dolog ('WARN: devid has existed '. $ devid); continue; // die ("{failure: true, msg: 'Duplicate device number '}");} $ SQL = "select type from devtype where name = '". $ devtype. "'"; $ devtype2 = $ db-> getRow ($ SQL); $ devtype = $ devtype2 ['type']; if (empty ($ devtype) or! Isset ($ devtype) {dolog ('WARN: dev type error epid :'. $ epid); continue; // die ("{failure: true, msg: 'Device type error '}");} $ SQL = "select id from dept where name = '". $ deptname. "'"; $ deptid = $ db-> getRow ($ SQL); $ deptid = $ deptid ['id']; if (empty ($ deptid) or! Isset ($ deptid) {dolog ('WARN: depa name error epid :'. $ epid); continue; // die ("{failure: true, msg: 'Unit name error '}");} if ($ bsl = 'yes ') {$ bsl = 1;} else {$ bsl = 0;} $ capability = ''; $ info = $ info. "; &"; $ insert = array ('epid' => $ epid, 'name' => $ epname, 'eptype' => $ eptype, 'devid' => $ devid, 'devtype' => $ devtype, 'Dept _ id' => $ deptid, 'bsl '=> $ bsl, 'info' => $ info, 'capability '=> $ capability); $ last _ Insert_epid = $ ep-> AddEp ($ insert); $ SQL = "replace into dept_has_ep (dept_id, ep_id) values ($ deptid, $ last_insert_epid )"; $ db-> query ($ SQL) or die ("{failure: true, msg: 'error 003 '}");} die (' {success: true, msg: '. json_encode ($ epfile ). '}'); // echo "{success: true, msg: 'Imported successfully'}";} if ($ _ GET ['file'] = 'car ') {$ epfile = $ _ FILES ['myfile'] ['tmp _ name']; $ data-> read ($ epfile); ini_set ('max _ execution_time ', '000000');/** device Import order: Unit name, license plate number, device type, Payment Amount */dolog ('numrows :'. $ data-> sheets [0] ['numrows ']. "--"); for ($ I = 1; $ I <= $ data-> sheets [0] ['numrows ']; $ I ++) {dolog ('-- I :'. $ I. "--"); $ name = $ data-> sheets [0] ['cells] [$ I] [1]; $ devid = $ data-> sheets [0] ['cells '] [$ I] [2]; $ dev = substr (trim ($ devid), 0, 3 ); if ($ dev! = '000000') {continue;} // $ eptype = $ data-> sheets [0] ['cells '] [$ I] [3]; $ SQL = "select count (*) as c from ep where name = '$ name'"; $ q = $ db-> getRow ($ SQL ); $ num = $ q ['c']; if ($ num) {$ SQL = "select id from ep where name = '$ name '"; $ q = $ db-> getRow ($ SQL); $ ep_id = $ q ['id']; // echo $ ep_id; $ SQL = "insert into dept_has_ep values (', 163, $ ep_id)"; echo $ SQL; $ db-> insert ($ SQL );}} // die ('{success: true, msg :'. json_encode ($ epfile ). '}') ;}?>

Importing dept cannot be implemented
Var FileFormdept = function () {}; Ext. apply (FileFormdept. prototype, {uploaddeptwindow: function () {fp = new Ext. formPanel ({fileUpload: true, width: 400, frame: true, autoHeight: true, bodyStyle: 'padding: 10px 10px 0 10px; ', labelWidth: 50, ULTS: {anchor: '200', allowBlank: false, msgTarget: 'Android'}, items: [{xtype: 'fileuploadfield ', id: 'form-file', emptyText: 'Select file ', fieldLabel: 'file', name: 'Dept', buttonText: 'browsed '}], buttons: [{text: 'upload', handler: function () {if (fp. getForm (). isValid () {fp. getForm (). submit ({url: 'file-upload. php? File = dept ', waitMsg: 'Upload file... ', success: function (form, action) {Ext. getCmp ('left-panel-refresh '). fireEvent ('click'); Ext. getCmp ('uploaddeptwindow '). close () ;}, failure: function (form, action) {Ext. msg. alert ('hprompt ', action. result. msg) ;}}}}, {text: 'reset ', handler: function () {fp. getForm (). reset () ;}}]}); uf = new Ext. window ({id: 'uploaddepptwindow', title: 'Upload file to be imported ', closable: true, modal: true, width: 410, // border: false, plain: true, items: [fp]}); uf. show ();}});





Reply to discussion (solution)

Can the user be imported successfully ?? Carefully check the loop section

Solved. thank you for your consideration.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.