コード例 #1
0
ファイル: Filesystem.php プロジェクト: richjoslin/rivety
	static function SureRemoveDir($dir, $DeleteMe) {
	    if (!$dh = @opendir($dir)) {
	    	return;
	    }
	    while (false !== ($obj = readdir($dh))) {
	        if($obj == '.' || $obj == '..') continue;
	        if (!@unlink($dir . '/' . $obj)) {
	        	SureRemoveDir($dir . '/' . $obj, true);
	        }
	    }
	    closedir($dh);
	    if ($DeleteMe) {
	        @rmdir($dir);
	    }
	}
コード例 #2
0
 public function run($sArgument)
 {
     if (!isset($sArgument) || !isset($sArgument[0]) || $sArgument[0] != 'yes') {
         die('This CLI command wipes a LimeSurvey installation clean (including all user except for the user ID 1 and user-uploaded content). For security reasons this command can only started if you add the parameter \'yes\' to the command line.');
     }
     Yii::import('application.helpers.common_helper', true);
     Yii::import('application.helpers.database_helper', true);
     $actquery = "truncate table {{assessments}}";
     Yii::app()->db->createCommand($actquery)->execute();
     $actquery = "truncate table {{answers}}";
     Yii::app()->db->createCommand($actquery)->execute();
     $actquery = "truncate table {{conditions}}";
     Yii::app()->db->createCommand($actquery)->execute();
     $actquery = "truncate table {{defaultvalues}}";
     Yii::app()->db->createCommand($actquery)->execute();
     $actquery = "truncate table {{labels}}";
     Yii::app()->db->createCommand($actquery)->execute();
     $actquery = "truncate table {{labelsets}}";
     Yii::app()->db->createCommand($actquery)->execute();
     $actquery = "truncate table {{groups}}";
     Yii::app()->db->createCommand($actquery)->execute();
     $actquery = "truncate table {{questions}}";
     Yii::app()->db->createCommand($actquery)->execute();
     $actquery = "truncate table {{surveys}}";
     Yii::app()->db->createCommand($actquery)->execute();
     $actquery = "truncate table {{surveys_languagesettings}}";
     Yii::app()->db->createCommand($actquery)->execute();
     $actquery = "delete from {{permissions}} where uid<>1";
     Yii::app()->db->createCommand($actquery)->execute();
     $actquery = "truncate table {{quota}}";
     Yii::app()->db->createCommand($actquery)->execute();
     $actquery = "truncate table {{quota_members}}";
     Yii::app()->db->createCommand($actquery)->execute();
     $actquery = "truncate table {{quota_languagesettings}}";
     Yii::app()->db->createCommand($actquery)->execute();
     $actquery = "truncate table {{question_attributes}}";
     Yii::app()->db->createCommand($actquery)->execute();
     $actquery = "truncate table {{user_groups}}";
     Yii::app()->db->createCommand($actquery)->execute();
     $actquery = "truncate table {{user_in_groups}}";
     Yii::app()->db->createCommand($actquery)->execute();
     $actquery = "truncate table {{templates}}";
     Yii::app()->db->createCommand($actquery)->execute();
     $actquery = "truncate table {{participants}}";
     Yii::app()->db->createCommand($actquery)->execute();
     $actquery = "truncate table {{participant_attribute_names}}";
     Yii::app()->db->createCommand($actquery)->execute();
     $actquery = "truncate table {{participant_attribute_names_lang}}";
     Yii::app()->db->createCommand($actquery)->execute();
     $actquery = "truncate table {{participant_attribute_values}}";
     Yii::app()->db->createCommand($actquery)->execute();
     $actquery = "truncate table {{participant_shares}}";
     Yii::app()->db->createCommand($actquery)->execute();
     $actquery = "truncate table {{failed_login_attempts}}";
     Yii::app()->db->createCommand($actquery)->execute();
     $actquery = "truncate table {{saved_control}}";
     Yii::app()->db->createCommand($actquery)->execute();
     $actquery = "truncate table {{survey_links}}";
     Yii::app()->db->createCommand($actquery)->execute();
     $actquery = "delete from {{users}} where uid<>1";
     Yii::app()->db->createCommand($actquery)->execute();
     $actquery = "update {{users}} set lang='en'";
     Yii::app()->db->createCommand($actquery)->execute();
     $surveyidresult = dbGetTablesLike("tokens%");
     foreach ($surveyidresult as $sv) {
         Yii::app()->db->createCommand("drop table " . $sv)->execute();
     }
     $surveyidresult = dbGetTablesLike("old\\_%");
     foreach ($surveyidresult as $sv) {
         Yii::app()->db->createCommand("drop table " . $sv)->execute();
     }
     $surveyidresult = dbGetTablesLike("survey\\_%");
     foreach ($surveyidresult as $sv) {
         if (strpos($sv, 'survey_links') === false && strpos($sv, 'survey_url_parameters') === false) {
             Yii::app()->db->createCommand("drop table " . $sv)->execute();
         }
     }
     $sBaseUploadDir = dirname(dirname(dirname(__FILE__))) . DIRECTORY_SEPARATOR . 'upload';
     SureRemoveDir($sBaseUploadDir . DIRECTORY_SEPARATOR . 'surveys', false);
     SureRemoveDir($sBaseUploadDir . DIRECTORY_SEPARATOR . 'templates', false);
 }
コード例 #3
0
function SureRemoveDir($dir)
{
    if (!($dh = @opendir($dir))) {
        return;
    }
    while ($obj = readdir($dh)) {
        if ($obj == '.' || $obj == '..') {
            continue;
        }
        if (!@unlink($dir . '/' . $obj)) {
            SureRemoveDir($dir . '/' . $obj);
        } else {
            $file_deleted++;
        }
    }
    if (@rmdir($dir)) {
        $dir_deleted++;
    }
}
コード例 #4
0
ファイル: investment_orgs.php プロジェクト: juslee/e27
    public function ajax_add($contributionid = "")
    {
        if (!$_SESSION['user'] && !$_SESSION['web_user']) {
            return false;
        }
        if (trim($_POST['name'])) {
            //check if company already exists
            $sql = "select `id` from `investment_orgs` where `name`=" . $this->db->escape(trim($_POST['name']));
            $q = $this->db->query($sql);
            $investment_org = $q->result_array();
        }
        $err = 0;
        if (!trim($_POST['name'])) {
            $err = 1;
            ?>
			alertX("<div class='red'>Please input a Name.</div>");
			<?php 
        } else {
            if ($investment_org[0]['id']) {
                $err = 1;
                ?>
			alertX("<div class='red'>Investment organization already exists in the database.</div>");
			<?php 
            } else {
                if (!trim($_POST['description'])) {
                    $err = 1;
                    ?>
			alertX("<div class='red'>Please input a Investment organization description.</div>");
			<?php 
                } else {
                    if (!checkEmail($_POST['email_address'])) {
                        $err = 1;
                        ?>
			alertX("<div class='red'>Please input a valid E-mail.</div>");
			<?php 
                    }
                }
            }
        }
        //save a contribution
        if ($_SESSION['web_user'] && $_POST['web_edit'] && !$err) {
            $sql = "insert into `contributions` set \n\t\t\t\t`web_user_id`='" . $_SESSION['web_user']['id'] . "',\n\t\t\t\t`table`='investment_orgs',\n\t\t\t\t`json_data`='" . mysql_real_escape_string(json_encode($_POST)) . "',\n\t\t\t\t`dateadded_ts` = '" . time() . "',\n\t\t\t\t`dateupdated_ts` = '" . time() . "',\n\t\t\t\t`approved` = 0\n\t\t\t";
            $this->db->query($sql);
            ?>
			alertX("<center>Thanks for the submission. It will be reviewed and approved shortly.</center>");
			setTimeout(function(){ self.location = self.location; }, 2000);
			self.location = self.location;
			//jQuery("#savebutton").val("Submit");
			//jQuery("#company_form *").attr("disabled", true);
			<?php 
            return false;
        }
        if (!$err) {
            $sql = "insert into `investment_orgs` set ";
            $arr = array();
            foreach ($_POST as $key => $value) {
                if (!is_array($value) && $key != 'sid') {
                    $arr[] = "`" . $key . "`=" . $this->db->escape(trim($value));
                }
            }
            if ($_POST['founded']) {
                $mdy = explode("/", $_POST['founded']);
                $arr[] = "`found_month` = " . $this->db->escape(trim($mdy[0]));
                $arr[] = "`found_day` = " . $this->db->escape(trim($mdy[1]));
                $arr[] = "`found_year` = " . $this->db->escape(trim($mdy[2]));
            }
            $sqlext = implode(", ", $arr);
            $sql .= $sqlext . ", `dateadded`=NOW(), `dateupdated`=NOW()";
            $q = $this->db->query($sql);
            $id = $this->db->insert_id();
            $this->slugify($id);
            //update logo url
            $logo = $_POST['logo'];
            if ($logo) {
                $logo = str_replace("temp/" . $_POST['sid'], $id, $logo);
                //replace sid with the company id
                $sql = "update `investment_orgs` set `logo`=" . $this->db->escape($logo) . " where `id`=" . $this->db->escape($id);
                $this->db->query($sql);
                //move files
                $from = dirname(__FILE__) . "/../../media/uploads/investment_orgs/temp/" . $_POST['sid'] . "/logo/" . urldecode(basename($logo));
                $folder = dirname(__FILE__) . "/../../media/uploads/investment_orgs/" . $id . "/";
                if (!is_dir($folder)) {
                    mkdir($folder, 0777);
                }
                $folder = $folder . "logo/";
                if (!is_dir($folder)) {
                    mkdir($folder, 0777);
                }
                $to = $folder . urldecode(basename($logo));
                rename($from, $to);
            }
            if (is_array($_POST['p_ids'])) {
                $sql = "delete from `investment_org_person` where `investment_org_id`=" . $this->db->escape($id);
                $this->db->query($sql);
                foreach ($_POST['p_ids'] as $key => $value) {
                    $start_date_ts = strtotime($_POST['p_start_dates'][$key]);
                    $end_date_ts = 0;
                    if ($_POST['p_end_dates'][$key]) {
                        $end_date_ts = strtotime($_POST['p_end_dates'][$key]);
                    }
                    $sql = "insert into `investment_org_person` set \n\t\t\t\t\t`investment_org_id`=" . $this->db->escape($id) . ", \n\t\t\t\t\t`person_id`=" . $this->db->escape($_POST['p_ids'][$key]) . ",\n\t\t\t\t\t`role`=" . $this->db->escape($_POST['p_roles'][$key]) . ",\n\t\t\t\t\t`start_date`=" . $this->db->escape($_POST['p_start_dates'][$key]) . ",\n\t\t\t\t\t`start_date_ts`=" . $this->db->escape($start_date_ts) . ",\n\t\t\t\t\t`end_date`=" . $this->db->escape($_POST['p_end_dates'][$key]) . ",\n\t\t\t\t\t`end_date_ts`=" . $this->db->escape($end_date_ts);
                    $this->db->query($sql);
                }
            }
            if ($_POST['sid']) {
                $dir = dirname(__FILE__) . "/../../media/uploads/investment_orgs/temp/" . $_POST['sid'];
                SureRemoveDir($dir, "true");
            }
            if ($contributionid) {
                $sql = "update `contributions` set `ipc_id`='" . $id . "', `approved`=1 where `id`='" . mysql_real_escape_string($contributionid) . "'";
                $q = $this->db->query($sql);
            }
            ?>
			alertX("Successfully Added Investment Organization '<?php 
            echo htmlentitiesX($_POST['name']);
            ?>
'.");
			//self.location = "<?php 
            echo site_url();
            ?>
investment_orgs/edit/<?php 
            echo $id;
            ?>
";
			<?php 
            if ($contributionid) {
                ?>
				self.location = "<?php 
                echo site_url();
                ?>
contributions";
				<?php 
            } else {
                ?>
				self.location = "<?php 
                echo site_url();
                ?>
investment_orgs/add";
				<?php 
            }
            $sql = "insert into `logs` set \n\t\t\t\t`action` = 'added',\n\t\t\t\t`table` = 'investment_orgs',\n\t\t\t\t`ipc_id` = " . $this->db->escape($id) . ",\n\t\t\t\t`name` = " . $this->db->escape(trim($_POST['name'])) . ",\n\t\t\t\t`user_id` = " . $this->db->escape(trim($_SESSION['user']['id'])) . ",\n\t\t\t\t`dateadded_ts` = " . time() . ",\n\t\t\t\t`dateadded` = NOW()\n\t\t\t";
            $this->db->query($sql);
        }
        ?>
		jQuery("#savebutton").val("Save");
		jQuery("#investment_org_form *").attr("disabled", false);
		<?php 
        exit;
    }
コード例 #5
0
 /**
  * Converts XML to PDF via DocBook
  * Requires special parameters in local.php to be set (see sample_local.php)
  * Uses articles2docbook_xml
  */
 function articles2docbook_pdf(&$xml, $params = array(), $mode = "PDF")
 {
     global $xmlg;
     $docbook_xml = $this->articles2docbook_xml($xml, $params, $params['add_gfdl']);
     # Create temporary directory
     $temp_dir = "MWC";
     $temp_dir .= substr(mt_rand(), 0, 4);
     $temp_dir = tempnam($params['docbook']['temp_dir'], $temp_dir);
     $project = basename($temp_dir);
     unlink($temp_dir);
     # It is currently a file, so...
     mkdir($temp_dir);
     # Write XML file
     $xml_file = $temp_dir . "/" . $project . ".xml";
     $handle = fopen($xml_file, 'wb');
     fwrite($handle, utf8_encode($docbook_xml));
     fclose($handle);
     if ($params['add_gfdl']) {
         copy($xmlg['sourcedir'] . "/gfdl.xml", $temp_dir . "/gfdl.xml");
     }
     if ($params['docbook']['out_dir']) {
         $output_dir = $params['docbook']['out_dir'];
     } else {
         $output_dir = $params['docbook']['temp_dir'];
     }
     # Call converter
     if ($mode == "PDF") {
         $command = str_replace("%1", $xml_file, $params['docbook']['command_pdf']);
         $out_subdir = 'pdf';
     } else {
         if ($mode == "HTML") {
             $command = str_replace("%1", $xml_file, $params['docbook']['command_html']);
             $out_subdir = 'html';
         }
     }
     # PHP4 does not have recursive mkdir
     $output_dir = $output_dir . '/' . $out_subdir;
     if (!file_exists($output_dir)) {
         mkdir($output_dir);
     }
     $output_dir = $output_dir . '/' . $project;
     if (!file_exists($output_dir)) {
         mkdir($output_dir);
     }
     $command = $command . ' --nochunks --output ' . $output_dir;
     exec($command);
     # Cleanup xml file
     SureRemoveDir($temp_dir);
     # Check if everything is OK
     $output_filename = $output_dir . '/' . $project . '.' . $out_subdir;
     if (!file_exists($output_filename)) {
         header('Content-type: text/html; charset=utf-8');
         print "ERROR : Document was not created: Docbook creator has failed! Command was: {$command}. output_filename = {$output_filename}";
     }
     # Return pdf filename
     return $output_filename;
 }
コード例 #6
0
ファイル: daemon.php プロジェクト: shishenkov/zpanel
function SureRemoveDir($dir, $DeleteMe)
{
    # DESCRIPTION: Removes all directories under a parent.
    # FUNCTION RELEASE: 5.0.0
    # FUNCTION AUTHOR: Bobby Allen (ballen@zpanel.co.uk)
    if (!($dh = @opendir($dir))) {
        return;
    }
    while (false !== ($obj = readdir($dh))) {
        if ($obj == '.' || $obj == '..') {
            continue;
        }
        if (!@unlink($dir . '/' . $obj)) {
            SureRemoveDir($dir . '/' . $obj, true);
        }
    }
    closedir($dh);
    if ($DeleteMe) {
        @rmdir($dir);
    }
}
コード例 #7
0
ファイル: module.inc.php プロジェクト: Blu2z/implsk
function DeleteFilesInDirectory($Directory)
{
    $win_Directory = str_replace("/", "\\", $Directory);
    if (substr(php_uname(), 0, 7) == "Windows") {
        chdir($win_Directory);
        $dir_list = recursive_listdir($win_Directory);
        for ($i = 0; $i < count($dir_list[files]); $i++) {
            unlink($dir_list[files][$i]);
        }
        for ($i = count($dir_list[dirs]) - 1; $i > -1; $i--) {
            rmdir($dir_list[dirs][$i]);
        }
    } else {
        SureRemoveDir($Directory);
    }
}
コード例 #8
0
ファイル: manager.php プロジェクト: Codechanic/The-Secretary
function emptyDir($dir, $DeleteMe)
{
    if (!($dh = @opendir($dir))) {
        return;
    }
    while (false !== ($obj = readdir($dh))) {
        if ($obj == '.' || $obj == '..') {
            continue;
        }
        if (!unlink($dir . '/' . $obj)) {
            SureRemoveDir($dir . '/' . $obj, true);
        }
    }
    closedir($dh);
    if ($DeleteMe) {
        rmdir($dir);
    }
}
コード例 #9
0
    function add()
    {
        // 		BusinessUnit -> build or take from policies
        // set the view page
        $this->LoadModel('BusinessUnit');
        $bussinessUnit = $this->BusinessUnit->find('list');
        $this->LoadModel('MrSourceKey');
        $sourceKeys = $this->MrSourceKey->find('list', array('fields' => array('_key', '_description')));
        $this->LoadModel('MrSourceControl');
        // 		$source_control = $this->MrSourceControl->find('list',array('fields'=>array('_key','source_company')));
        $src_control = $this->MrSourceControl->find('all');
        $this->LoadModel('MrSourceAccount');
        $source_control[0] = '-- New --';
        foreach ($src_control as $id_source => $source_control_name) {
            $source_control[$source_control_name['MrSourceControl']['id']] = $source_control_name['MrSourceControl']['source_company'] . " " . $sourceKeys[$source_control_name['MrSourceControl']['_key']];
        }
        if (empty($source_control)) {
            $source_control = null;
        }
        $this->set(compact('bussinessUnit', 'sourceKeys', 'source_control'));
        // 		debug($this->data);exit();
        if (!empty($this->data)) {
            // 			build the index reference of the menu accounts
            /** NOTE <if build a new record go through this search if exist and delete all asscociated records>**/
            if (isset($this->data['MrSourceControl']['source_company']) and isset($this->data['MrSourceControl']['_key'])) {
                /** NOTE @debug */
                // 	debug($this->data);exit();
                $bussinessUnitSource = $bussinessUnit[$this->data['MrSourceControl']['source_company']];
                $conditionsSourceControl['MrSourceControl.source_company'] = $bussinessUnitSource;
                $conditionsSourceControl['MrSourceControl._key'] = $this->data['MrSourceControl']['_key'];
                $source_control = $this->MrSourceControl->find('list', array('fields' => array('id', 'source_company'), 'conditions' => $conditionsSourceControl));
                $this->MrSourceControl->id = key($source_control);
                if (!empty($this->MrSourceControl->id)) {
                    // 					delete(int $id = null, boolean $cascade = true);
                    $mr_source_controls_id = $this->MrSourceControl->id;
                    $this->MrSourceControl->delete($this->MrSourceControl->id, TRUE);
                    // 					debug('id found =>'.$mr_source_controls_id);
                    // 					debug($this->MrSourceAccount->find('count',array('conditions'=>array('MrSourceAccount.mr_source_controls_id'=>$mr_source_controls_id))));
                    if (!$this->MrSourceAccount->deleteAll(array('MrSourceAccount.mr_source_controls_id' => $mr_source_controls_id), TRUE)) {
                        $this->Session->setFlash(__('<div class="alert alert-danger alert-dismissible fade in" role="alert">
														<button type="button" class="close" data-dismiss="alert" aria-label="Close">
															<span aria-hidden="true">&times;</span>
														</button>
														<strong> Ocurrio un error at 0x000000127 </strong>
														sus datos no pudieron ser borrados correctamente , intentelo de nuevo
													</div>', true));
                        $this->redirect(array('action' => 'add'));
                    }
                }
                $MrSourceControl['MrSourceControl']['id'] = NULL;
                $MrSourceControl['MrSourceControl']['source_company'] = $bussinessUnitSource;
                $MrSourceControl['MrSourceControl']['_key'] = $this->data['MrSourceControl']['_key'];
                $MrSourceControl['MrSourceControl']['_generate'] = FALSE;
                $MrSourceControl['MrSourceControl']['_status'] = $this->data['MrSourceAccount']['_status'];
                $this->MrSourceControl->create();
                if (!$this->MrSourceControl->save($MrSourceControl['MrSourceControl'])) {
                    $this->Session->setFlash(__('<div class="alert alert-danger alert-dismissible fade in" role="alert">
														<button type="button" class="close" data-dismiss="alert" aria-label="Close">
															<span aria-hidden="true">&times;</span>
														</button>
														<strong> Ocurrio un error at 0x000000121 </strong>
														sus datos no pudieron ser guardados correctamente , intentelo de nuevo
													</div>', true));
                    $this->redirect(array('action' => 'add'));
                }
                // 				$MrSourceControlId = $this->MrSourceControl->getLastInsertID();
                $src_ctrl = $this->MrSourceControl->findById($this->MrSourceControl->getLastInsertID());
            } else {
                $src_ctrl = $this->MrSourceControl->findById($this->data['MrSourceAccount']['source_company_id']);
            }
            /** NOTE <if source_replace is checked the delete and add the new records otherwise just add>*/
            if (isset($this->data['MrSourceAccount']['source_replace'])) {
                $account_company = $bussinessUnit[$this->data['MrSourceAccount']['company']];
                // 				debug($this->MrSourceAccount->find('count',array('conditions'=>array('MrSourceAccount.mr_source_controls_id'=>$src_ctrl['MrSourceControl']['id'],'MrSourceAccount._key'=>$src_ctrl['MrSourceControl']['_key'],'MrSourceAccount.company'=>$account_company))));
                /** NOTE @debug */
                // 	debug($src_ctrl);
                // 	debug($this->data);exit();
                if (!$this->MrSourceAccount->deleteAll(array('MrSourceAccount.mr_source_controls_id' => $src_ctrl['MrSourceControl']['id'], 'MrSourceAccount._key' => $src_ctrl['MrSourceControl']['_key'], 'MrSourceAccount.company' => $account_company), TRUE)) {
                    $this->Session->setFlash(__('<div class="alert alert-danger alert-dismissible fade in" role="alert">
													<button type="button" class="close" data-dismiss="alert" aria-label="Close">
														<span aria-hidden="true">&times;</span>
													</button>
													<strong> Ocurrio un error at 0x000000127 </strong>
													sus datos no pudieron ser borrados correctamente , intentelo de nuevo
												</div>', true));
                }
            }
            $mime[0] = 'text/plain';
            $mime[1] = 'text/csv';
            $mime[2] = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
            $this->data['MrSourceAccount']['mr_source_controls_id'] = $src_ctrl['MrSourceControl']['id'];
            $this->data['MrSourceAccount']['source_company'] = $src_ctrl['MrSourceControl']['source_company'];
            $this->data['MrSourceAccount']['company'] = $bussinessUnit[$this->data['MrSourceAccount']['company']];
            $this->data['MrSourceAccount']['_key'] = $src_ctrl['MrSourceControl']['_key'];
            /** NOTE @debug */
            // 			debug($this->data['MrSourceAccount']);
            // 	debug($this->data);exit();
            /** <get user information> **/
            $_username = $_SESSION['Auth']['User']['username'];
            $_datetime = date('Y-m-d H:m:s');
            $_ip = $_SERVER['REMOTE_ADDR'];
            // if comes directly from MR define and create a dir to handle xlsx files
            $bin_dir = WWW_ROOT . 'files' . DS . 'mr_source' . DS . 'bin' . DS;
            mkdir($bin_dir, 0777, true);
            // 			if (!mkdir($bin_dir, 0777, true)) {
            // 				die('Failed to create folders...');
            // 			}
            // 			$xml = simplexml_load_file($bin_dir.'sharedStrings.xml');
            // 			$json = json_encode($xml);
            // 			$arrayx = json_decode($json,TRUE);
            // 			debug($arrayx);
            if (strtolower(end(explode('.', $this->data['MrSourceAccount']['upload']['name']))) !== 'xls' and strtolower(end(explode('.', $this->data['MrSourceAccount']['upload']['name']))) !== 'csv' and strtolower(end(explode('.', $this->data['MrSourceAccount']['upload']['name']))) !== 'xlsx') {
                $this->Session->setFlash(__('<div class="alert alert-danger alert-dismissible fade in" role="alert">
												<button type="button" class="close" data-dismiss="alert" aria-label="Close">
													<span aria-hidden="true">&times;</span>
												</button>
												<strong> Solo se permiten archivos de texto plano o archivos de excel 2003 con la extension csv, xls o xlsx </strong>
											</div>', true));
                $this->redirect(array('action' => 'add'));
            } else {
                $ext = '.' . strtolower(end(explode('.', $this->data['MrSourceAccount']['upload']['name'])));
            }
            $name = basename(md5($this->data['MrSourceAccount']['upload']['name']));
            // for the long and inconsistent names and drop the basename /tmp
            move_uploaded_file($this->data['MrSourceAccount']['upload']['tmp_name'], WWW_ROOT . 'files' . DS . 'mr_source' . DS . $name . $ext);
            $file = WWW_ROOT . 'files' . DS . 'mr_source' . DS . $name . $ext;
            var_dump($ext);
            // maybe we can use a swicth approach
            if ($ext === '.xls') {
                $filename = WWW_ROOT . 'files' . DS . 'mr_source' . DS . $name;
                $this->convertXLStoCSV($file, $filename . '.csv');
                $file_csv = $filename . '.csv';
            } else {
                if ($ext === '.csv') {
                    $file_csv = $file;
                    // 				var_dump($file_csv);
                } else {
                    if ($ext === '.xlsx') {
                        // 				load the scrappy file exported from the Management Reported of Microsoft puaj!
                        // unzip the xlsx file
                        $zip = new ZipArchive();
                        $zip->open($file);
                        $zip->extractTo($bin_dir);
                        $zip->close();
                        // load the xml containing the accounts definitions this is the file and phpexcel can handle MR exporting files! yet
                        $xml = simplexml_load_file($bin_dir . 'sharedStrings.xml');
                        $csv_file = fopen(WWW_ROOT . 'files' . DS . 'mr_source' . DS . $name . '.csv', 'w');
                        // 				write to csv file
                        foreach ($xml->si as $si) {
                            fputcsv($csv_file, get_object_vars($si), ',', '"');
                        }
                        fclose($csv_file);
                        // 				export the path for treatment
                        $file_csv = WWW_ROOT . 'files' . DS . 'mr_source' . DS . $name . '.csv';
                        //clean the unzipped file and save space
                        SureRemoveDir($bin_dir, FALSE);
                        // 				debug($file_csv);
                    } else {
                        $this->redirect(array('action' => 'add'));
                    }
                }
            }
            $lines = file($file_csv, FILE_SKIP_EMPTY_LINES);
            foreach ($lines as $line_num => $line) {
                // 				command
                // 				sed -e '1,3d' costosFijosOpOri_viewl.csv | sed '$d' | sed '$d' | sed 's/^"//g' | cut -c 1-35 | sed 's/-//g' > /disk/costos/accounts.csv
                // 				echo "<b>".substr($line,0,1)."</b>";
                // 				echo "Line #<b>{$line_num}</b> : " . htmlspecialchars($line) . "<br />\n";
                // 				if comes from excel file MAX version supported is 2003
                if (substr($line, 0, 1) === '"' and substr($line, 1, 1) != '0') {
                    unset($line);
                }
                // 				or if comes from csv directly
                if (substr($line, 0, 1) != '"' and substr($line, 0, 1) != '0') {
                    unset($line);
                }
                if (isset($line)) {
                    if (substr($line, 0, 1) === '"') {
                        $line = utf8_encode(str_replace('"', '', $line));
                    }
                    $string_replaced = str_replace('-', '', str_split($line, 35)[0]);
                    /** NOTE <search for the account but ask if you want this (just for performance) > */
                    if ($this->data['MrSourceAccount']['some_check']) {
                        // ask to database if the account exist in an existing mr_source_controls_id
                        $conditions_some_check['MrSourceAccount.SubAccount'] = $string_replaced;
                        $conditions_some_check['MrSourceAccount.company'] = $this->data['MrSourceAccount']['company'];
                        $conditions_some_check['MrSourceAccount.source_company'] = $this->data['MrSourceAccount']['source_company'];
                        $conditions_some_check['MrSourceAccount.mr_source_controls_id'] = $this->data['MrSourceAccount']['mr_source_controls_id'];
                        $conditions_some_check['MrSourceAccount._key'] = $this->data['MrSourceAccount']['_key'];
                        $are_you_there = $this->MrSourceAccount->find('count', array('conditions' => $conditions_some_check));
                        if (!$are_you_there) {
                            $account_build['SubAccount'] = $string_replaced;
                            $account_build['company'] = $this->data['MrSourceAccount']['company'];
                            $account_build['source_company'] = $this->data['MrSourceAccount']['source_company'];
                            $account_build['mr_source_controls_id'] = $this->data['MrSourceAccount']['mr_source_controls_id'];
                            $account_build['_key'] = $this->data['MrSourceAccount']['_key'];
                            $account_build['_status'] = $this->data['MrSourceAccount']['_status'];
                            $accounts_menu['MrSourceAccount'][] = $account_build;
                        }
                    } else {
                        /** NOTE <search for the account but ask if you want this (just for performance) > */
                        $account_build['SubAccount'] = $string_replaced;
                        $account_build['company'] = $this->data['MrSourceAccount']['company'];
                        $account_build['source_company'] = $this->data['MrSourceAccount']['source_company'];
                        $account_build['mr_source_controls_id'] = $this->data['MrSourceAccount']['mr_source_controls_id'];
                        $account_build['_key'] = $this->data['MrSourceAccount']['_key'];
                        $account_build['_status'] = $this->data['MrSourceAccount']['_status'];
                        $accounts_menu['MrSourceAccount'][] = $account_build;
                    }
                }
            }
            // end foreach line
            debug($accounts_menu);
            // 			exit();
            if ($this->MrSourceAccount->saveAll($accounts_menu['MrSourceAccount'])) {
                $this->Session->setFlash(__('<div class="alert alert-success alert-dismissible fade in" role="alert">
						<button type="button" class="close" data-dismiss="alert" aria-label="Close">
							<span aria-hidden="true">&times;</span>
						</button>
						<strong>Sus archivo de datos se ha Guardado</strong>
						ahora puede volver al
						<a href="' . $this->webroot . '" class="alert-link">Inicio del Portal</a>
					</div>', true));
            } else {
                $this->Session->setFlash(__('<div class="alert alert-success alert-dismissible fade in" role="alert">
												<button type="button" class="close" data-dismiss="alert" aria-label="Close">
													<span aria-hidden="true">&times;</span>
												</button>
												<strong>Su archivo de datos no pudo guardarse correctamente!</strong>
												puede volver al
												<a href="' . $this->webroot . '" class="alert-link">Inicio del Portal</a>
												o intentarlo de nuevo
											</div>', true));
            }
            // 			$this->redirect($this->referer());
            $this->redirect(array('controller' => 'MrSourceControls', 'action' => 'index'));
            // 			exit();
        }
    }
コード例 #10
0
ファイル: w2x.php プロジェクト: sivareddyg/utils
                                        header('Content-Type: application/pdf');
                                        header("Content-Length: " . (string) filesize($filename));
                                        header('Content-Disposition: attachment; filename="' . $xmlg["book_title"] . '.pdf"');
                                    } else {
                                        if ($format == "docbook_html") {
                                            header('Content-Type: text/html');
                                            header("Content-Length: " . (string) filesize($filename));
                                            header('Content-Disposition: inline; filename="' . $xmlg["book_title"] . '.html"');
                                        }
                                    }
                                    fpassthru($fp);
                                    fclose($fp);
                                }
                                # Cleanup
                                $pdf_dir = dirname(dirname($filename));
                                SureRemoveDir($pdf_dir);
                                @rmdir($pdf_dir);
                            }
                        }
                    }
                }
            }
        }
    }
    xml_cleanup($xml);
    exit;
} else {
    # Show the form
    if (!defined('MEDIAWIKI')) {
        # Stand-alone
        header('Content-type: text/html; charset=utf-8');
コード例 #11
0
ファイル: zpanel_kernel.php プロジェクト: shishenkov/zpanel
function zapi_filesystem_remove($folder)
{
    if (file_exists($folder)) {
        SureRemoveDir($folder, true);
    }
    return;
}
コード例 #12
0
    function add()
    {
        // 		BusinessUnit -> build or take from policies
        // set the view page
        $this->LoadModel('BusinessUnit');
        $bussinessUnit = $this->BusinessUnit->find('list');
        $this->LoadModel('MrSourceKey');
        $sourceKeys = $this->MrSourceKey->find('list', array('fields' => array('_key', '_description')));
        $this->LoadModel('MrSourceControl');
        // 		$source_control = $this->MrSourceControl->find('list',array('fields'=>array('_key','source_company')));
        $src_control = $this->MrSourceControl->find('all');
        // 		$source_control[0] = '-- New --';
        foreach ($src_control as $id_source => $source_control_name) {
            $source_control[$source_control_name['MrSourceControl']['id']] = $source_control_name['MrSourceControl']['source_company'] . " " . $sourceKeys[$source_control_name['MrSourceControl']['_key']];
        }
        if (empty($source_control)) {
            $source_control = null;
        }
        $this->set(compact('bussinessUnit', 'sourceKeys', 'source_control'));
        if (!empty($this->data)) {
            // 			debug($this->MrSourceConfig->query("select * from integraapp.dbo.getCostos('201511','|','TBKORI','OF')"));
            // 			if (!function_exists('mssql_min_message_severity')) {
            // 				trigger_error(__("PHP SQL Server interface is not installed", true), E_USER_WARNING);
            // 			}
            /** NOTE <search and delete section build from mr_source_controls_controller>*/
            //re-build the date
            if (isset($this->data['MrSourceConfig']['period'])) {
                $date = explode('/', $this->data['MrSourceConfig']['period']);
                $period = $date[2] . $date[1];
                $this->data['MrSourceConfig']['period'] = $period;
            }
            // search for the selected key
            $source_ctrl = $this->MrSourceControl->findById($this->data['MrSourceAccount']['source_company_id']);
            // 				debug($source_ctrl);
            // 				$bussinessUnitSource = $bussinessUnit[$this->data['MrSourceAccount']['source_company_id']];
            $bussinessUnit_ = $bussinessUnit[$this->data['MrSourceAccount']['company']];
            $conditionsSourceConfig['MrSourceConfig.source_company'] = $source_ctrl['MrSourceControl']['source_company'];
            $conditionsSourceConfig['MrSourceConfig.company'] = $bussinessUnit_;
            $conditionsSourceConfig['MrSourceConfig._key'] = $source_ctrl['MrSourceControl']['_key'];
            $conditionsSourceConfig['MrSourceConfig.period'] = $this->data['MrSourceConfig']['period'];
            // 				var_dump($conditionsSourceConfig);
            $source_config = $this->MrSourceConfig->find('list', array('fields' => array('id', 'source_company'), 'conditions' => $conditionsSourceConfig));
            // 				debug($source_config);
            $this->data['MrSourceConfig']['_key'] = $source_ctrl['MrSourceControl']['_key'];
            $this->data['MrSourceConfig']['source_company'] = $source_ctrl['MrSourceControl']['source_company'];
            $this->data['MrSourceConfig']['company'] = $bussinessUnit_;
            if (isset($this->data['MrSourceConfig']['source_replace'])) {
                if (!$this->MrSourceConfig->deleteAll(array($conditionsSourceConfig), TRUE)) {
                    $this->Session->setFlash(__('<div class="alert alert-danger alert-dismissible fade in" role="alert">
													<button type="button" class="close" data-dismiss="alert" aria-label="Close">
														<span aria-hidden="true">&times;</span>
													</button>
													<strong> Ocurrio un error at 0x000000127 </strong>
													sus datos no pudieron ser borrados correctamente , intentelo de nuevo
												</div>', true));
                    $this->redirect(array('action' => 'add'));
                }
            }
            /** NOTE <search and delete section build from mr_source_controls_controller>*/
            $mime[0] = 'text/plain';
            $mime[1] = 'text/csv';
            $mime[2] = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
            /** <get user information> **/
            $_username = $_SESSION['Auth']['User']['username'];
            $_datetime = date('Y-m-d H:m:s');
            $_ip = $_SERVER['REMOTE_ADDR'];
            // if comes directly from MR define and create a dir to handle xlsx files
            $bin_dir = WWW_ROOT . 'files' . DS . 'mr_source' . DS . 'bin' . DS;
            mkdir($bin_dir, 0777, true);
            // 			if (!mkdir($bin_dir, 0777, true)) {
            // 				die('Failed to create folders...');
            // 			}
            // 			$xml = simplexml_load_file($bin_dir.'sharedStrings.xml');
            // 			$json = json_encode($xml);
            // 			$arrayx = json_decode($json,TRUE);
            // 			debug($arrayx);
            if (strtolower(end(explode('.', $this->data['MrSourceConfig']['upload']['name']))) !== 'xls' and strtolower(end(explode('.', $this->data['MrSourceConfig']['upload']['name']))) !== 'csv' and strtolower(end(explode('.', $this->data['MrSourceConfig']['upload']['name']))) !== 'xlsx') {
                $this->Session->setFlash(__('<div class="alert alert-danger alert-dismissible fade in" role="alert">
												<button type="button" class="close" data-dismiss="alert" aria-label="Close">
													<span aria-hidden="true">&times;</span>
												</button>
												<strong> Solo se permiten archivos de texto plano o archivos de excel 2003 con la extension csv, xls o xlsx </strong>
											</div>', true));
                $this->redirect(array('action' => 'add'));
            } else {
                $ext = '.' . strtolower(end(explode('.', $this->data['MrSourceConfig']['upload']['name'])));
            }
            $name = basename(md5($this->data['MrSourceConfig']['upload']['name']));
            // for the long and inconsistent names and drop the basename /tmp
            move_uploaded_file($this->data['MrSourceConfig']['upload']['tmp_name'], WWW_ROOT . 'files' . DS . 'mr_source' . DS . $name . $ext);
            $file = WWW_ROOT . 'files' . DS . 'mr_source' . DS . $name . $ext;
            var_dump($ext);
            // maybe we can use a swicth approach
            if ($ext === '.xls') {
                $filename = WWW_ROOT . 'files' . DS . 'mr_source' . DS . $name;
                $this->convertXLStoCSV($file, $filename . '.csv');
                $file_csv = $filename . '.csv';
            } else {
                if ($ext === '.csv') {
                    $file_csv = $file;
                    // 				var_dump($file_csv);
                } else {
                    if ($ext === '.xlsx') {
                        // 				load the scrappy file exported from the Management Reported of Microsoft puaj!
                        // unzip the xlsx file
                        $zip = new ZipArchive();
                        $zip->open($file);
                        $zip->extractTo($bin_dir);
                        $zip->close();
                        // load the xml containing the accounts definitions this is the file and phpexcel can handle MR exporting files! yet
                        $xml = simplexml_load_file($bin_dir . 'sharedStrings.xml');
                        $csv_file = fopen(WWW_ROOT . 'files' . DS . 'mr_source' . DS . $name . '.csv', 'w');
                        // 				write to csv file
                        foreach ($xml->si as $si) {
                            fputcsv($csv_file, get_object_vars($si), ',', '"');
                        }
                        fclose($csv_file);
                        // 				export the path for treatment
                        $file_csv = WWW_ROOT . 'files' . DS . 'mr_source' . DS . $name . '.csv';
                        //clean the unzipped file and save space
                        SureRemoveDir($bin_dir, FALSE);
                        // 				debug($file_csv);
                    } else {
                        $this->redirect(array('action' => 'add'));
                    }
                }
            }
            $lines = file($file_csv, FILE_SKIP_EMPTY_LINES);
            foreach ($lines as $line_num => $line) {
                // 				command
                // 				sed -e '1,3d' costosFijosOpOri_viewl.csv | sed '$d' | sed '$d' | sed 's/^"//g' | cut -c 1-35 | sed 's/-//g' > /disk/costos/accounts.csv
                // 				echo "<b>".substr($line,0,1)."</b>";
                // 				echo "Line #<b>{$line_num}</b> : " . htmlspecialchars($line) . "<br />\n";
                // 				if comes from excel file MAX version supported is 2003
                if (substr($line, 0, 1) === '"' and substr($line, 1, 1) != '0') {
                    unset($line);
                }
                // 				or if comes from csv directly
                if (substr($line, 0, 1) != '"' and substr($line, 0, 1) != '0') {
                    unset($line);
                }
                if (isset($line)) {
                    if (substr($line, 0, 1) === '"') {
                        $line = utf8_encode(str_replace('"', '', $line));
                    }
                    $string_replaced = str_replace('-', '', str_split($line, 35)[0]);
                    $account_build['SubAccount'] = $string_replaced;
                    $account_build['company'] = $this->data['MrSourceConfig']['company'];
                    $account_build['source_company'] = $this->data['MrSourceConfig']['source_company'];
                    $account_build['period'] = $this->data['MrSourceConfig']['period'];
                    $account_build['_key'] = $this->data['MrSourceConfig']['_key'];
                    $account_build['_status'] = $this->data['MrSourceConfig']['_status'];
                    $accounts_menu['MrSourceConfig'][] = $account_build;
                }
            }
            // end foreach line
            debug($accounts_menu);
            if ($this->MrSourceConfig->saveAll($accounts_menu['MrSourceConfig'])) {
                /** NOTE <mssql_procedure re-build the mr_source_account and set a proper msg to inform on success >*/
                $_source_company = $this->data['MrSourceConfig']['source_company'];
                $_period = $this->data['MrSourceConfig']['period'];
                $_key = $this->data['MrSourceConfig']['_key'];
                if ($this->MrSourceConfig->query("exec sistemas.dbo.setDataMr N'{$_period}', N'|', N'{$_source_company}',N'{$_key}';")) {
                    $this->Session->setFlash(__('<div class="alert alert-success alert-dismissible fade in" role="alert">
								<button type="button" class="close" data-dismiss="alert" aria-label="Close">
									<span aria-hidden="true">&times;</span>
								</button>
								<strong>Sus archivo de datos se ha Guardado y se han Actualizado los nuevos datos en la DB</strong>
								ahora puede volver al
								<a href="' . $this->webroot . '" class="alert-link">Inicio del Portal</a>
							</div>', true));
                }
            } else {
                $this->Session->setFlash(__('<div class="alert alert-success alert-dismissible fade in" role="alert">
												<button type="button" class="close" data-dismiss="alert" aria-label="Close">
													<span aria-hidden="true">&times;</span>
												</button>
												<strong>Su archivo de datos no pudo guardarse correctamente!</strong>
												puede volver al
												<a href="' . $this->webroot . '" class="alert-link">Inicio del Portal</a>
												o intentarlo de nuevo
											</div>', true));
            }
            $this->redirect($this->referer());
            // 			maybe you want execute an procedure from hir
        }
    }
コード例 #13
0
ファイル: project.php プロジェクト: avilleret/Rekall
function update()
{
    $retours = array("success" => 0, "error" => "", "value" => "");
    if (!file_exists("create.zip")) {
        $retours["value"] .= "Download of create.zip... ";
        downloadFile("http://project.memorekall.fr/create.zip", "create.zip");
    }
    $zip = new ZipArchive();
    $res = $zip->open("create.zip");
    if ($res === TRUE) {
        $retours["value"] .= "Moving files... ";
        rename("../file", "../file_cpy");
        $retours["value"] .= "Unzipping... ";
        $zip->extractTo("../");
        $zip->close();
        $retours["value"] .= "Cleaning... ";
        SureRemoveDir("../file", true);
        $retours["value"] .= "Moving files... ";
        rename("../file_cpy", "../file");
        $retours["value"] .= "Cleaning update... ";
        unlink("create.zip");
        $retours["success"] = 1;
    } else {
        $retours["success"] = -1;
        $retours["error"] = "No seed found";
    }
    echo json_encode($retours);
}