+
+ function admin()
+ {
+ $this->t->set_file(array('admin_t' => 'admin.tpl'));
+ $this->t->set_block('admin_t','upload','uploadhandle');
+ $this->t->set_block('admin_t','admin','adminhandle');
+ $this->t->set_block('admin_t','cmd','cmdhandle');
+
+ $this->t->set_var('upload_action',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.admin&action=upload'));
+
+ $action = get_var('action',array('GET','POST'));
+
+ $this->t->pfp('out','admin_t');
+
+ if($action == 'upload')
+ {
+ $target_path = $this->upload_target_path . basename( $_FILES['uploadedfile']['name']);
+
+ if(($_FILES['uploadedfile']['type'] == "application/zip") &&
+ (move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path))) {
+ $uploadstatus = "<b>The following file was uploaded successfully: </b><br><br>";
+ $uploadstatus.= "Filename : " . $_FILES['uploadedfile']['name'] . "<br>";
+ $uploadstatus.= "Type : " . $_FILES['uploadedfile']['type'] . "<br>";
+ $uploadstatus.= "Size : " . $_FILES['uploadedfile']['size'] . "<br>";
+ $this->t->set_var('uploadstatus',$uploadstatus);
+ $this->t->pfp('uploadhandle','upload');
+ $this->t->set_var('uploadhandle','');
+ print "<table border=1 width=80%><tr><td>\n<pre>";
+
+ # make a directory for this data to be stored in
+ $date="data_" . date("Y_m_d");
+ $data_dir = $this->upload_target_path . $date;
+ print "-> Making the data directory: $date<br>\n";
+ exec('mkdir ' . $data_dir . ' 2>&1', $result, $return_code);
+ if($return_code != 0) {
+ print implode('\n',$result) . "<br>";
+ print "<b><font color=red>";
+ print "-E- Unable to create the data directory. Aborting import.";
+ print "</font></b>";
+ return 0;
+ }
+
+ # move the file uploaded into this directory
+ print "-> Moving the uploaded file into the data dir<br>\n";
+ exec('mv ' . $target_path . ' ' . $data_dir . '/' . ' 2>&1', $result, $return_code);
+ if($return_code != 0) {
+ print implode('\n',$result) . "<br>";
+ print "<b><font color=red>";
+ print "-E- Unable to move the uploaded file into the data dir. Aborting import.";
+ print "</font></b>";
+ return 0;
+ }
+
+ # unzip the data into this directory
+ print "-> Unzipping the data<br>\n";
+ $data_file = $data_dir . '';
+ exec('unzip ' . $data_dir . '/*.zip -d ' . $data_dir . ' 2>&1', $result, $return_code);
+ if($return_code != 0) {
+ print implode('\n',$result) . "<br>";
+ print "<b><font color=red>";
+ print "-E- Unable to unzip the uploaded file into the data dir. Aborting import.";
+ print "</font></b>";
+ return 0;
+ }
+ exec('mv ' . $data_dir . '/*/* '. $data_dir . ' 2>&1', $result, $return_code);
+
+ # update the data_latest link to point to this new directory
+ print "-> Updating the latest data dir link<br>\n";
+ $data_latest = $this->upload_target_path . 'data_latest';
+ exec('rm ' . $data_latest. '; ln -s ' . $data_dir .' '. $data_latest .' 2>&1', $result, $return_code);
+ if($return_code != 0) {
+ print implode('\n',$result) . "<br>";
+ print "<b><font color=red>";
+ print "-E- Unable to update the data latest link. Aborting import.";
+ print "</font></b>";
+ return 0;
+ }
+
+ # run the import perl script to encorporate it into the DB
+ ob_start('ob_logstdout', 2);
+ print "-> Importing the data into the EQ database<br>\n";
+ ob_flush(); flush(); sleep(1);
+ $import_log = $this->upload_target_path . '/import.log';
+ $data_log = $this->upload_target_path . '/data.log';
+ $import_cmd = $this->script_path . 'import_ward_data ' . $data_latest . ' | tee ' . $import_log;
+ $parse_cmd = $this->script_path . 'parse_ward_data -v ' . $data_latest . ' > ' . $data_log;
+ #print "import_cmd: $import_cmd<br>";
+ #print "parse_cmd: $parse_cmd<br>";
+ ob_start('ob_logstdout', 2);
+ passthru($import_cmd);
+ passthru($parse_cmd);
+ ob_flush(); flush(); sleep(1);
+
+ # fix the permissions of the data dir
+ exec('chmod -R o-rwx ' . $data_dir, $result, $return_code);
+
+ $this->t->pfp('cmdhandle','cmd');
+ print "</pre></td></tr></table>";
+
+ } else if($_FILES['uploadedfile']['type'] != "application/zip") {
+ $uploadstatus = "<b><font color=red>The file format must be a .zip file, please try again! </font></b>";
+ $this->t->set_var('uploadstatus',$uploadstatus);
+
+ } else {
+ $uploadstatus = "<b><font color=red> There was an error (" . $_FILES['uploadedfile']['error'];
+ $uploadstatus.= ") uploading the file, please try again! </font></b>";
+ $this->t->set_var('uploadstatus',$uploadstatus);
+ }
+ }
+ else
+ {
+ $this->t->set_var('adminhandle','');
+ $this->t->pfp('adminhandle','admin');
+ }
+
+ $this->save_sessiondata();
+ }