Ejemplo n.º 1
0
 public function upload()
 {
     if (!$this->input['video_id']) {
         $this->errorOutput(NOID);
     }
     $sql = " SELECT video_base_path,video_path,video_filename,id FROM " . DB_PREFIX . "vodinfo WHERE id IN (" . $this->input['video_id'] . ")";
     $q = $this->db->query($sql);
     $video = array();
     while ($r = $this->db->fetch_array($q)) {
         $video[] = $r;
     }
     //实例化ftp,并连接
     $ftp_config = array('hostname' => $this->input['hostname'], 'username' => $this->input['username'], 'password' => $this->input['password']);
     $ftp = new Ftp();
     if (!$ftp->connect($ftp_config)) {
         $this->errorOutput('CAN NOT CONNECT FTP SERVER');
     }
     foreach ($video as $k => $v) {
         $target_dir = date('Y', TIMENOW) . '/' . date('m', TIMENOW) . '/' . TIMENOW . hg_rand_num(6) . '/';
         $target_path = $target_dir . $v['video_filename'];
         $video_filepath = $v['video_base_path'] . $v['video_path'] . $v['video_filename'];
         if (!$ftp->mkdir($target_dir)) {
             $this->errorOutput('CAN NOT MAKE DIR');
         }
         if (!$ftp->upload($video_filepath, $target_path)) {
             $this->errorOutput('CAN NOT UPLOAD FILE');
         }
         $pathinfo = pathinfo($target_path);
         $filename = basename($pathinfo['basename'], '.' . $pathinfo['extension']);
         $this->addItem(array('path' => $target_path, 'id' => $v['id'], 'dir' => $pathinfo['dirname'], 'filename' => $filename));
     }
     $this->output();
 }
 /**
  * @param DatabaseBackupFile $file
  * @return ResultObject[]
  */
 public function process(DatabaseBackupFile $file)
 {
     $d = $file->getBackupDate();
     $results = [];
     foreach ($this->uploadsCredentials as $credentials) {
         $result = new ResultObject();
         // empty ResultObject means all is OK
         $backupPath = $credentials['path'] . '/' . $d->format('Y') . '/' . $d->format('F');
         $entireFilePath = $backupPath . '/' . $file->getFileName();
         try {
             $ftp = new \Ftp();
             $ftp->connect($credentials['host']);
             $ftp->login($credentials['username'], $credentials['password']);
             if (!$ftp->fileExists($backupPath)) {
                 $ftp->mkDirRecursive($backupPath);
             }
             $ftp->put($entireFilePath, $file->getFilePath(), FTP_BINARY);
             $ftp->close();
         } catch (\FtpException $e) {
             $this->logger->addCritical(sprintf('Uploading backup file\'s failed. %s', $e));
             $result->addError('Zálohu se nepodařilo nahrát na: ' . $credentials['host'], 'error');
         }
         $results[] = $result;
     }
     return $results;
 }
Ejemplo n.º 3
0
 /**
  * Returns a new Ftp object. If you do not define the "file" parameter,
  *
  *     $ftp = static::factory('group');
  *
  * @param   string  Ftp filename
  * @param   array   array of values
  * @return  Ftp
  */
 public static function factory($config = 'default', $connect = true)
 {
     $ftp = new Ftp($config);
     // Unless told not to, connect automatically
     $connect === true and $ftp->connect();
     return $ftp;
 }
Ejemplo n.º 4
0
 /**
  * Ist für den Abgleich der Bestellungen im Cronjob.
  */
 public function update()
 {
     global $selectline, $oxid, $ftp;
     $this->set_log('Cronjob: ' . date('d.m.Y H:i:s') . "\r\n");
     try {
         $ftp = new Ftp();
         $ftp->connect($oxid['ftp_host']);
         $ftp->login($oxid['ftp_user'], $oxid['ftp_password']);
         $ftp->close();
     } catch (Exception $e) {
         $this->set_log('SelectConnect konnte keine Verbindung zum FTP-Server herstellen!');
         exit;
     }
     if (!oxid_userlogin()) {
         $this->set_log('SelectConnect konnte sich nicht bei Oxid einloggen!');
         exit;
     }
     if (!$this->is_current_update_process()) {
         $this->set_log("Cronjob wurde gestartet \r\n");
         $this->set_lock_file();
         $last_update = $this->get_last_update();
         $this->set_log("Bestellungen werden in Selectline importiert \r\n");
         $orders = $oxid['db']->get_results("SELECT * FROM " . $oxid['table_order'] . " WHERE OXFOLDER  = '" . $oxid['get_order_status'] . "' ORDER BY OXORDERNR");
         if ($orders) {
             foreach ($orders as $order) {
                 $order_products = $oxid['db']->get_results("SELECT * FROM " . $oxid['table_orderarticles'] . " WHERE OXORDERID = '" . $order->OXID . "' ");
                 $order->products = $order_products;
                 $order_payment = $oxid['db']->get_row("SELECT * FROM " . $oxid['table_payments'] . " WHERE ('" . $order->OXPAYMENTTYPE . "' = OXID)");
                 $order->payment = $order_payment;
                 $this->set_order_to_selectline($order, true);
                 $oxid['db']->query("UPDATE " . $oxid['table_order'] . " SET OXFOLDER = '" . $oxid['set_order_status'] . "', OXEXPORT = 1 WHERE `OXID` = '" . $order->OXID . "' ");
             }
         }
         $this->set_log("Bestellungstatus wird abgeglichen \r\n");
         $orders = $selectline['db']->get_results("SELECT * FROM " . $selectline['table_orders'] . " WHERE [Belegtyp] = '" . $selectline['filter_order_invoice'] . "' AND [BearbeitetAm] >= CONVERT(datetime, '" . $last_update->format('d.m.Y H:i:s') . "',104)");
         if ($orders) {
             foreach ($orders as $order) {
                 $tracking_id = $this->get_tracking_id_from_selectline($order);
                 $updateArray = array('OXBILLNR' => $order->Belegnummer, 'OXBILLDATE' => $order->Datum->format('Y-m-d'), 'OXSENDDATE' => $order->Datum->format('Y-m-d H:i:s'), 'OXFOLDER' => $oxid['order_status_finish']);
                 if ($tracking_id !== NULL) {
                     $updateArray['OXTRACKCODE'] = $tracking_id;
                 }
                 //print_r($this->format_update_query($oxid['table_order'], $updateArray, array('OXORDERNR' => str_replace('OX', '', $order->IhrAuftrag))));
                 $oxid['db']->query($this->format_update_query($oxid['table_order'], $updateArray, array('OXORDERNR' => str_replace('OX', '', $order->IhrAuftrag))));
                 $this->set_log("Bestellung " . $order->IhrAuftrag . "/" . $order->Belegnummer . " - Status: FINISHED - Tracking: " . $tracking_id . " \r\n");
             }
         }
         $this->set_last_update();
         $this->remove_lock_file();
         $this->set_log("Cron wurde beendet \r\n");
         $this->set_log("\r\n##################################\r\n\r\n");
     } else {
         print_r('Error: Es läuft bereits Update-Prozess.');
     }
 }
Ejemplo n.º 5
0
 /**
  * Download test.
  * @return void
  */
 public function testDownload()
 {
     $ftp = new Ftp();
     // Opens an FTP connection to the specified host
     $ftp->connect('ftp.nettephp.com');
     $ftp->pasv(TRUE);
     // Login with username and password
     $ftp->login('*****@*****.**', 'anonymous');
     // Download file 'README' to local temporary file
     $temp = tmpfile();
     $ftp->fget($temp, 'README', Ftp::ASCII);
     // echo file
     fseek($temp, 0);
     $this->assertEquals("Nette Framework rocks!", stream_get_contents($temp));
 }
function get_ftp_content($source, $target)
{
    $result = false;
    $config = array('hostname' => FTP_HOST, 'username' => FTP_USER, 'password' => FTP_PASSWORD, 'port' => FTP_PORT, 'timeout' => FTP_TIMEOUT);
    $ftp = new Ftp();
    $ftp->connect($config);
    if ($ftp->existsFile($source)) {
        $result = $ftp->download($source, $target);
    } else {
        access_log('log', 'No documents.');
        //clear_file();
    }
    $ftp->close();
    return $result;
}
Ejemplo n.º 7
0
 public function forward_suobei($id)
 {
     //获取视频id
     $sql = 'SELECT content_id,vodid FROM ' . DB_PREFIX . 'materials WHERE content_id IN (' . $id . ') AND vodid !=""';
     $query = $this->db->query($sql);
     $k = array();
     while ($row = $this->db->fetch_array($query)) {
         $k[$row['content_id']] = $row['vodid'];
     }
     $ids = '';
     $ret = array();
     if (!empty($k)) {
         //获取视频信息
         $ids = implode(',', $k);
         $keys = array_keys($k);
         $vodpath = array();
         //获取报料标题
         $sql = 'SELECT id,title FROM ' . DB_PREFIX . 'content WHERE id IN (' . implode(',', $keys) . ')';
         $query = $this->db->query($sql);
         $title = array();
         while ($row = $this->db->fetch_array($query)) {
             $title[$row['id']] = $row['title'];
         }
         $title = array_combine($k, $title);
         $ftp = $this->settings['App_suobei']['ftp'];
         $ids = implode(',', $k);
         $ret = $this->get_vodinfo($ids, $ftp['host'], $ftp['username'], $ftp['password']);
         $vodpath = array();
         if (!empty($ret) && is_array($ret)) {
             foreach ($ret as $key => $val) {
                 $vodpath[$val['id']] = $ret[$key];
             }
         } else {
             $this->errorOutput('ftp上传失败');
         }
     }
     if (!empty($vodpath) && !empty($title)) {
         //获取报料标题
         //写xml文件
         $this->vod_xml($vodpath, $title);
         //ftp上传
         //实例化ftp,并连接
         $ftp_config = array('hostname' => $ftp['host'], 'username' => $ftp['username'], 'password' => $ftp['password']);
         $ftp_up = new Ftp();
         if (!$ftp_up->connect($ftp_config)) {
             $this->errorOutput('CAN NOT CONNECT FTP SERVER');
         }
         foreach ($vodpath as $k => $v) {
             $target_dir = $v['dir'] . '/';
             $target_path = $target_dir . $v['filename'] . '.xml';
             $xml_filepath = $this->settings['App_suobei']['xmldir'] . $v['filename'] . '.xml';
             if (!file_exists($xml_filepath)) {
                 $this->errorOutput('CAN NOT FIND XML');
             }
             if (!$ftp_up->mkdir($target_dir)) {
                 $this->errorOutput('CAN NOT MAKE DIR');
             }
             if (!$ftp_up->upload($xml_filepath, $target_path)) {
                 $this->errorOutput('CAN NOT UPLOAD FILE');
             }
         }
         $ftp_up->close();
         //更新状态位
         $sql = 'UPDATE ' . DB_PREFIX . 'content SET suobei=1 WHERE id IN (' . implode(',', $keys) . ')';
         $this->db->query($sql);
     }
     return $id;
 }
Ejemplo n.º 8
0
	<link href='css/style.css' rel='stylesheet' type='text/css'>

	<script src="js/jquery-2.1.3.min.js"></script>
	<script src="js/jQuery.ajaxQueue.js"></script>
	<script src="bootstrap/js/bootstrap.min.js"></script>
	<script src="bootstrap/js/bootstrap-select.min.js"></script>

</head>
<body class="<?php 
echo $action;
?>
">
<?php 
try {
    $ftp = new Ftp();
    $ftp->connect($oxid['ftp_host']);
    $ftp->login($oxid['ftp_user'], $oxid['ftp_password']);
    $ftp->close();
} catch (Exception $e) {
    print_r('<p class="alert alert-danger">SelectConnect konnte keine Verbindung zum FTP-Server herstellen!</p>');
    $action = 'error';
}
if (!oxid_userlogin()) {
    print_r('<p class="alert alert-danger">SelectConnect konnte sich nicht bei Oxid einloggen!</p>');
    $action = 'error';
}
switch ($action) {
    case 'orders':
        $orders = new Orders();
        $items = $orders->import();
        ?>
Ejemplo n.º 9
0
        $extarr = explode('.', $filename);
        return end($extarr);
    }
    /**
     * 从后缀扩展定义FTP传输模式  ascii 或 binary
     *
     * @access  private
     * @param   string  后缀扩展
     * @return  string
     */
    private function _settype($ext)
    {
        $text_type = array('txt', 'text', 'php', 'phps', 'php4', 'js', 'css', 'htm', 'html', 'phtml', 'shtml', 'log', 'xml');
        return in_array($ext, $text_type) ? 'ascii' : 'binary';
    }
    /**
     * 错误日志记录
     *
     * @access  prvate
     * @return  boolean
     */
    private function _error($msg)
    {
        return @file_put_contents('ftp_err.log', "date[" . date("Y-m-d H:i:s") . "]-hostname[" . $this->hostname . "]-username[" . $this->username . "]-password[" . $this->password . "]-msg[" . $msg . "]\n", FILE_APPEND);
    }
}
$config = array('hostname' => 'localhost', 'username' => 'root', 'password' => 'root', 'port' => 21);
$ftp = new Ftp();
$ftp->connect($config);
$ftp->upload('1.txt', 'ftp_upload.log');
//$ftp->download('ftp_upload.log','ftp_download.log');
Ejemplo n.º 10
0
 public function upload2ftp()
 {
     $config = json_decode($this->input['config'], 1);
     $files = json_decode($this->input['files'], 1);
     include_once ROOT_PATH . 'lib/class/ftp.class.php';
     $ftp = new Ftp();
     $server_dir = trim($config['server_dir'], '/');
     $app_dir = $config['app_dir'];
     $message = array('error' => 0);
     if (!$ftp->connect($config)) {
         $message['error'] = 1;
         $message['message'] = '连接服务器失败[' . $config['hostname'] . ']';
     }
     if ($server_dir && !$message['error']) {
         if (!$ftp->mkdir($server_dir)) {
             $message['error'] = 2;
             $message['message'] = '目标目录不存在且创建失败[' . $server_dir . ']';
         }
     }
     if (!$files && !$message['error']) {
         $message['error'] = 3;
         $message['message'] = '文件列表不存在[' . $files . ']';
     }
     if (!$message['error']) {
         foreach ($files as $file) {
             if (!file_exists($file)) {
                 //continue;
             }
             //返回上传错误的文件
             $dfile = str_replace($app_dir, '', $file);
             //如果设定了ftp目标目录
             $dfile = $server_dir ? $server_dir . $dfile : $dfile;
             $upload_dir = trim(str_replace('/' . basename($file), '', $dfile), '/');
             if ($upload_dir) {
                 $ftp->mkdir($upload_dir);
             }
             if (!$ftp->upload($file, $dfile)) {
                 $message['error'] = 4;
                 $message['message'][$file] = $dfile;
             }
         }
     }
     //file_put_contents(CACHE_DIR . 'debug.txt', var_export($config,1));
     $ftp->close();
     $this->addItem($message);
     $this->output();
 }
Ejemplo n.º 11
0
Archivo: login.php Proyecto: ssrsfs/blg
<?php

$db = Typeframe::Database();
$pm = Typeframe::Pagemill();
if ($_POST['cmd'] == 'login') {
    $ftp = new Ftp();
    if (!$ftp->connect(TYPEF_FTP_HOST)) {
        Typeframe::Log("Failed to connect to FTP at '" . TYPEF_FTP_HOST . "'");
        $pm->addLoop('errors', array('message' => "Could not connect to '" . TYPEF_FTP_HOST . "'"));
    } else {
        if (!$ftp->login($_POST['username'], $_POST['password'])) {
            Typeframe::Log('FTP login failed');
            $pm->addLoop('errors', array('message' => "Login failed."));
        } else {
            Typeframe::Log('FTP login succeeded');
            $_SESSION['typef_ftp_user'] = $_POST['username'];
            $_SESSION['typef_ftp_pass'] = $_POST['password'];
            Typeframe::Redirect('FTP login confirmed.', $_POST['redirect']);
            return;
        }
    }
    $pm->setVariable('redirect', $_POST['redirect']);
}
Ejemplo n.º 12
0
<?php

$db = Typeframe::Database();
$pm = Typeframe::Pagemill();
if (empty($_SESSION['typef_ftp_user']) || empty($_SESSION['typef_ftp_pass'])) {
    if (defined('TYPEF_FTP_USER') && defined('TYPEF_FTP_PASS') && TYPEF_FTP_USER != '') {
        // Test the provided credentials
        $ftp = new Ftp();
        $ftp->connect(TYPEF_FTP_HOST) or die('Invalid FTP host.');
        if ($ftp->login(TYPEF_FTP_USER, TYPEF_FTP_PASS)) {
            $_SESSION['typef_ftp_user'] = TYPEF_FTP_USER;
            $_SESSION['typef_ftp_pass'] = TYPEF_FTP_PASS;
            $ftp->close();
            return;
        }
    }
    $pm->setVariable('redirect', $_SERVER['REQUEST_URI']);
    Typeframe::SetPageTemplate('/admin/ftp/login.html');
    Typeframe::CurrentPage()->stop();
}
Ejemplo n.º 13
0
function do_create($type, $data, $detail)
{
    global $user_detail;
    $time_now = time();
    if ($type == 'user') {
        $data['email_address'] = strtolower($data['email_address']);
        if (!check_permission('add_administrator', $user_detail['user_id']) && $data['account_type'] != 2) {
            global $errormessage;
            $errormessage = 'You are not permitted to add users that are not in the Advertiser group.';
            return false;
        }
        if (empty($data['first_name']) or empty($data['last_name']) or empty($data['email_address']) or empty($data['new_password']) or empty($data['new_password_2'])) {
            global $errormessage;
            $errormessage = 'Please fill out all required fields.';
            global $editdata;
            $editdata = $data;
            return false;
        }
        if ($data['new_password_2'] != $data['new_password']) {
            global $errormessage;
            $errormessage = 'The passwords you entered do not match.';
            global $editdata;
            $editdata = $data;
            return false;
        }
        if (username_exists($data['email_address'])) {
            global $errormessage;
            $errormessage = 'A user with this e-mail address already exists in the system.';
            global $editdata;
            $editdata = $data;
            return false;
        }
        $data['password_md5'] = md5($data['new_password']);
        $creation_date = time();
        $data['first_name'] = sanitize($data['first_name']);
        $data['last_name'] = sanitize($data['last_name']);
        $data['company_name'] = sanitize($data['company_name']);
        $data['phone_number'] = sanitize($data['phone_number']);
        $data['fax_number'] = sanitize($data['fax_number']);
        $data['company_address'] = sanitize($data['company_address']);
        $data['company_city'] = sanitize($data['company_city']);
        $data['company_state'] = sanitize($data['company_state']);
        $data['company_zip'] = sanitize($data['company_zip']);
        $data['company_country'] = sanitize($data['company_country']);
        $data['tax_id'] = sanitize($data['tax_id']);
        $data['account_type'] = sanitize($data['account_type']);
        global $maindb;
        mysql_query("INSERT INTO md_uaccounts (email_address, pass_word, account_status, account_type, company_name, first_name, last_name, phone_number, fax_number, company_address, company_city, company_state, company_zip, company_country, tax_id, creation_date)\nVALUES ('{$data['email_address']}', '{$data['password_md5']}', '1', '{$data['account_type']}', '{$data['company_name']}', '{$data['first_name']}', '{$data['last_name']}', '{$data['phone_number']}', '{$data['fax_number']}', '{$data['company_address']}', '{$data['company_city']}', '{$data['company_state']}', '{$data['company_zip']}', '{$data['company_country']}', '{$data['tax_id']}', '{$creation_date}')", $maindb);
        global $created_user_id;
        $created_user_id = mysql_insert_id($maindb);
        create_rightset('user', $created_user_id, $data);
        return true;
    }
    if ($type == 'group') {
        if (empty($data['group_name'])) {
            global $errormessage;
            $errormessage = 'Please enter a group name.';
            global $editdata;
            $editdata = $data;
            return false;
        }
        global $maindb;
        mysql_query("INSERT INTO md_user_groups (group_name, group_status)\nVALUES ('{$data['group_name']}', '1')", $maindb);
        global $created_group_id;
        $created_group_id = mysql_insert_id($maindb);
        create_rightset('group', $created_group_id, $data);
        return true;
    }
    if ($type == 'channel') {
        if (empty($data['channel_name'])) {
            global $errormessage;
            $errormessage = 'Please enter a channel name.';
            global $editdata;
            $editdata = $data;
            return false;
        }
        global $maindb;
        mysql_query("INSERT INTO md_channels (channel_type, channel_name)\nVALUES ('1', '{$data['channel_name']}')", $maindb);
        return true;
    }
    if ($type == 'creativeserver') {
        if (empty($data['server_name']) or empty($data['remote_host']) or empty($data['remote_user']) or empty($data['remote_password']) or empty($data['remote_directory']) or empty($data['server_default_url'])) {
            global $errormessage;
            $errormessage = 'Please fill out all required fields.';
            global $editdata;
            $editdata = $data;
            return false;
        }
        $data['server_type'] = sanitize($data['server_type']);
        $data['server_name'] = sanitize($data['server_name']);
        $data['remote_host'] = sanitize($data['remote_host']);
        $data['remote_user'] = sanitize($data['remote_user']);
        $data['remote_password'] = sanitize($data['remote_password']);
        $data['remote_directory'] = sanitize($data['remote_directory']);
        $data['server_default_url'] = sanitize($data['server_default_url']);
        global $maindb;
        mysql_query("INSERT INTO md_creative_servers (server_type, server_name, remote_host, remote_user, remote_password, remote_directory, server_default_url, server_status)\nVALUES ('{$data['server_type']}', '{$data['server_name']}', '{$data['remote_host']}', '{$data['remote_user']}', '{$data['remote_password']}', '{$data['remote_directory']}', '{$data['server_default_url']}', '1')", $maindb);
        return true;
    }
    if ($type == 'ad_unit') {
        if (empty($data['adv_name']) or $data['creative_format'] == 10 && (!is_numeric($data['custom_creative_width']) or !is_numeric($data['custom_creative_height']))) {
            global $errormessage;
            $errormessage = 'Please fill out all required fields.';
            global $editdata;
            $editdata = $data;
            return false;
        }
        if (!is_numeric($data['creative_format'])) {
            global $errormessage;
            $errormessage = 'Please choose a creative size for your ad.';
            global $editdata;
            $editdata = $data;
            return false;
        }
        if ($data['creative_type'] == 3) {
            if (empty($data['html_body'])) {
                global $errormessage;
                $errormessage = 'Please enter a HTML body for your ad.';
                global $editdata;
                $editdata = $data;
                return false;
            }
        }
        if ($data['creative_type'] == 2) {
            if (empty($data['creative_url']) or empty($data['click_url'])) {
                global $errormessage;
                $errormessage = 'Please enter a Creative URL and Click URL for your ad.';
                global $editdata;
                $editdata = $data;
                return false;
            }
        }
        if ($data['creative_type'] == 1) {
            if (empty($data['click_url'])) {
                global $errormessage;
                $errormessage = 'Please enter a Click URL for your ad.';
                global $editdata;
                $editdata = $data;
                return false;
            }
            if (!file_exists($_FILES['creative_file']['tmp_name']) || !is_uploaded_file($_FILES['creative_file']['tmp_name'])) {
                global $errormessage;
                $errormessage = 'Please upload a creative for your ad unit.';
                global $editdata;
                $editdata = $data;
                return false;
            }
        }
        // Define Image Sizes
        if ($data['creative_format'] == 1) {
            $data['custom_creative_width'] = 320;
            $data['custom_creative_height'] = 50;
        }
        if ($data['creative_format'] == 2) {
            $data['custom_creative_width'] = 300;
            $data['custom_creative_height'] = 250;
        }
        if ($data['creative_format'] == 3) {
            $data['custom_creative_width'] = 728;
            $data['custom_creative_height'] = 90;
        }
        if ($data['creative_format'] == 4) {
            $data['custom_creative_width'] = 160;
            $data['custom_creative_height'] = 600;
        }
        if ($data['creative_format'] == 5) {
            $data['custom_creative_width'] = 300;
            $data['custom_creative_height'] = 50;
        }
        if ($data['creative_format'] == 6) {
            $data['custom_creative_width'] = 320;
            $data['custom_creative_height'] = 480;
        }
        // End Define Image Sizes
        // IF CREATIVE TYPE =1, ATTEMPT TO UPLOAD CREATIVE
        if ($data['creative_type'] == 1) {
            $creative_server = getconfig_var('default_creative_server');
            // Generate Creative Hash
            $uniqid = uniqid(time());
            $creative_hash = md5($uniqid);
            $file_extension = strtolower(substr(strrchr($_FILES['creative_file']['name'], "."), 1));
            // Case: Remote Creative Server (FTP)
            if (getconfig_var('default_creative_server') > 1) {
                list($width, $height, $type, $attr) = getimagesize($_FILES['creative_file']['tmp_name']);
                if ($height != $data['custom_creative_height'] or $width != $data['custom_creative_width'] or empty($file_extension)) {
                    global $errormessage;
                    $errormessage = 'The image you uploaded does not appear to be in the right dimensions. Please upload a valid image sized ' . $data['custom_creative_width'] . 'x' . $data['custom_creative_height'] . '';
                    global $editdata;
                    $editdata = $data;
                    return false;
                }
                $creative_server_detail = get_creativeserver_detail(getconfig_var('default_creative_server'));
                if ($creative_server_detail['entry_id'] < 1) {
                    global $errormessage;
                    $errormessage = 'The default creative server does not seem to exist. Please change your creative server in your mAdserve control panel under Configuration>Creative Servers';
                    global $editdata;
                    $editdata = $data;
                    return false;
                }
                // Attempt: Upload
                include MAD_PATH . '/modules/ftp/ftp.class.php';
                try {
                    $ftp = new Ftp();
                    $ftp->connect($creative_server_detail['remote_host']);
                    $ftp->login($creative_server_detail[remote_user], $creative_server_detail[remote_password]);
                    $ftp->put($creative_server_detail[remote_directory] . $creative_hash . '.' . $file_extension, $_FILES['creative_file']['tmp_name'], FTP_BINARY);
                } catch (FtpException $e) {
                    global $errormessage;
                    $errormessage = 'FTP Client was unable to upload creative to remote server. Error given: ' . $e->getMessage() . '';
                    global $editdata;
                    $editdata = $data;
                    return false;
                }
                // End: Upload
            }
            // End Case: Remote Creative Server (FTP)
            // Case: Local Creative Server
            if (getconfig_var('default_creative_server') == 1) {
                include MAD_PATH . '/modules/upload/class.upload.php';
                $handle = new Upload($_FILES['creative_file']);
                $handle->allowed = array('image/*');
                $handle->file_new_name_body = $creative_hash;
                if ($handle->uploaded) {
                    $image_width = $handle->image_src_x;
                    $image_height = $handle->image_src_y;
                    if (!empty($image_width) && !empty($image_height) && ($image_height != $data['custom_creative_height'] or $image_width != $data['custom_creative_width'])) {
                        global $errormessage;
                        $errormessage = 'The image you uploaded does not appear to be in the right dimensions. Please upload an image sized ' . $data['custom_creative_width'] . 'x' . $data['custom_creative_height'] . '';
                        global $editdata;
                        $editdata = $data;
                        return false;
                    }
                    $handle->Process(MAD_PATH . MAD_CREATIVE_DIR);
                    if ($handle->processed) {
                        // OK
                    } else {
                        global $errormessage;
                        $errormessage = 'Creative could not be uploaded. Please check if your creative directory is writeable (' . MAD_CREATIVE_DIR . ') and that you have uploaded a valid image file.';
                        global $editdata;
                        $editdata = $data;
                        return false;
                    }
                } else {
                    // Not OK
                    global $errormessage;
                    $errormessage = 'Creative could not be uploaded. Please check if your creative directory is writeable (' . MAD_CREATIVE_DIR . ') and that you have uploaded a valid image file.';
                    global $editdata;
                    $editdata = $data;
                    return false;
                }
            }
            // End Case: Local Creative Sercer
        }
        // END CREATIVE UPLOAD
        global $maindb;
        // Insert Ad Unit into DB
        if (!isset($creative_server)) {
            $creative_server = '';
        }
        if (!isset($creative_hash)) {
            $creative_hash = '';
        }
        if (!isset($file_extension)) {
            $file_extension = '';
        }
        if (!isset($data['adv_mraid'])) {
            $data['adv_mraid'] = '';
        }
        $data['creative_type'] = sanitize($data['creative_type']);
        $data['click_url'] = sanitize($data['click_url']);
        $data['html_body'] = sanitize($data['html_body']);
        $data['creative_url'] = sanitize($data['creative_url']);
        $data['tracking_pixel'] = sanitize($data['tracking_pixel']);
        $data['adv_name'] = sanitize($data['adv_name']);
        $data['custom_creative_height'] = sanitize($data['custom_creative_height']);
        $data['custom_creative_width'] = sanitize($data['custom_creative_width']);
        $data['adv_mraid'] = sanitize($data['adv_mraid']);
        mysql_query("INSERT INTO md_ad_units (campaign_id, unit_hash, adv_type, adv_status, adv_click_url, adv_click_opentype, adv_chtml, adv_bannerurl, adv_impression_tracking_url, adv_name, adv_clickthrough_type, adv_creative_extension, adv_height, adv_width, creativeserver_id, adv_mraid)\nVALUES ('{$data['campaign_id']}', '{$creative_hash}', '{$data['creative_type']}', '1', '{$data['click_url']}', '', '{$data['html_body']}', '{$data['creative_url']}', '{$data['tracking_pixel']}', '{$data['adv_name']}', '', '{$file_extension}', '{$data['custom_creative_height']}', '{$data['custom_creative_width']}', '{$creative_server}', '{$data['adv_mraid']}')", $maindb);
        global $created_adunit_id;
        $created_adunit_id = mysql_insert_id($maindb);
        // END: Insert Ad Unit into DB
        return true;
    }
    if ($type == 'campaign') {
        if (!isset($data['as_values_1'])) {
            $data['as_values_1'] = '';
        }
        if (!isset($data['placement_select'])) {
            $data['placement_select'] = '';
        }
        if (!isset($data['channel_select'])) {
            $data['channel_select'] = '';
        }
        if (!isset($data['target_iphone'])) {
            $data['target_iphone'] = '';
        }
        if (!isset($data['target_ipod'])) {
            $data['target_ipod'] = '';
        }
        if (!isset($data['target_ipad'])) {
            $data['target_ipad'] = '';
        }
        if (!isset($data['target_android'])) {
            $data['target_android'] = '';
        }
        if (!isset($data['target_other'])) {
            $data['target_other'] = '';
        }
        $countries_active = 0;
        $separate_countries = explode(',', $data['as_values_1']);
        foreach ($separate_countries as $my_tag) {
            if (!empty($my_tag)) {
                $countries_active = 1;
            }
        }
        if (!is_numeric($data['campaign_priority']) or empty($data['campaign_name'])) {
            global $errormessage;
            $errormessage = 'Please fill out all required fields.';
            global $editdata;
            $editdata = $data;
            return false;
        }
        if ($data['geo_targeting'] == 2 && $countries_active != 1) {
            global $errormessage;
            $errormessage = 'Please select at least one country you want to target.';
            global $editdata;
            $editdata = $data;
            return false;
        }
        if ($data['publication_targeting'] == 2 && count($data['placement_select']) < 1) {
            global $errormessage;
            $errormessage = 'Please select at least one placement you want to target.';
            global $editdata;
            $editdata = $data;
            return false;
        }
        if ($data['channel_targeting'] == 2 && count($data['channel_select']) < 1) {
            global $errormessage;
            $errormessage = 'Please select at least one channel you want to target.';
            global $editdata;
            $editdata = $data;
            return false;
        }
        if ($data['device_targeting'] == 2 && ($data['target_iphone'] != 1 && $data['target_ipod'] != 1 && $data['target_ipad'] != 1 && $data['target_android'] != 1 && $data['target_other'] != 1)) {
            global $errormessage;
            $errormessage = 'Please select at least one device type you want to target.';
            global $editdata;
            $editdata = $data;
            return false;
        }
        if ($data['campaign_type'] == 'network' && !is_numeric($data['campaign_networkid'])) {
            global $errormessage;
            $errormessage = 'Please select an ad network to send your campaign traffic to.';
            global $editdata;
            $editdata = $data;
            return false;
        }
        if (!empty($data['total_amount']) && !is_numeric($data['total_amount'])) {
            global $errormessage;
            $errormessage = 'Your daily cap needs to be a numeric value.';
            global $editdata;
            $editdata = $data;
            return false;
        }
        if ($data['campaign_type'] != 'network') {
            if (empty($data['adv_name']) or $data['creative_format'] == 10 && (!is_numeric($data['custom_creative_width']) or !is_numeric($data['custom_creative_height']))) {
                global $errormessage;
                $errormessage = 'Please fill out all required fields.';
                global $editdata;
                $editdata = $data;
                return false;
            }
            if (!is_numeric($data['creative_format'])) {
                global $errormessage;
                $errormessage = 'Please choose a creative size for your ad.';
                global $editdata;
                $editdata = $data;
                return false;
            }
            if ($data['creative_type'] == 3) {
                if (empty($data['html_body'])) {
                    global $errormessage;
                    $errormessage = 'Please enter a HTML body for your ad.';
                    global $editdata;
                    $editdata = $data;
                    return false;
                }
            }
            if ($data['creative_type'] == 2) {
                if (empty($data['creative_url']) or empty($data['click_url'])) {
                    global $errormessage;
                    $errormessage = 'Please enter a Creative URL and Click URL for your ad.';
                    global $editdata;
                    $editdata = $data;
                    return false;
                }
            }
            if ($data['creative_type'] == 1) {
                if (empty($data['click_url'])) {
                    global $errormessage;
                    $errormessage = 'Please enter a Click URL for your ad.';
                    global $editdata;
                    $editdata = $data;
                    return false;
                }
                if (!file_exists($_FILES['creative_file']['tmp_name']) || !is_uploaded_file($_FILES['creative_file']['tmp_name'])) {
                    global $errormessage;
                    $errormessage = 'Please upload a creative for your ad unit.';
                    global $editdata;
                    $editdata = $data;
                    return false;
                }
            }
            if ($data['start_date_type'] == 2 && empty($data['startdate_value'])) {
                global $errormessage;
                $errormessage = 'Please choose a start date for your campaign.';
                global $editdata;
                $editdata = $data;
                return false;
            }
            if ($data['end_date_type'] == 2 && empty($data['enddate_value'])) {
                global $errormessage;
                $errormessage = 'Please choose an end date for your campaign.';
                global $editdata;
                $editdata = $data;
                return false;
            }
            if ($data['start_date_type'] == 2) {
                $start_date = explode('/', $data['startdate_value']);
                $start_date_array['year'] = $start_date[2];
                $start_date_array['day'] = $start_date[1];
                $start_date_array['month'] = $start_date[0];
                $start_date_array['unix'] = strtotime("{$start_date_array['year']}-{$start_date_array['month']}-{$start_date_array['day']}");
            }
            if ($data['end_date_type'] == 2) {
                $end_date = explode('/', $data['enddate_value']);
                $end_date_array['year'] = $end_date[2];
                $end_date_array['day'] = $end_date[1];
                $end_date_array['month'] = $end_date[0];
                $end_date_array['unix'] = strtotime("{$end_date_array['year']}-{$end_date_array['month']}-{$end_date_array['day']}");
            }
            if ($data['end_date_type'] == 2 && $end_date_array['unix'] < time()) {
                global $errormessage;
                $errormessage = 'The end date you entered is in the past. Please choose an end date in the future.';
                global $editdata;
                $editdata = $data;
                return false;
            }
            // Define Image Sizes
            if ($data['creative_format'] == 1) {
                $data['custom_creative_width'] = 320;
                $data['custom_creative_height'] = 50;
            }
            if ($data['creative_format'] == 2) {
                $data['custom_creative_width'] = 300;
                $data['custom_creative_height'] = 250;
            }
            if ($data['creative_format'] == 3) {
                $data['custom_creative_width'] = 728;
                $data['custom_creative_height'] = 90;
            }
            if ($data['creative_format'] == 4) {
                $data['custom_creative_width'] = 160;
                $data['custom_creative_height'] = 600;
            }
            if ($data['creative_format'] == 5) {
                $data['custom_creative_width'] = 300;
                $data['custom_creative_height'] = 50;
            }
            if ($data['creative_format'] == 6) {
                $data['custom_creative_width'] = 320;
                $data['custom_creative_height'] = 480;
            }
            // End Define Image Sizes
            // IF CREATIVE TYPE =1, ATTEMPT TO UPLOAD CREATIVE
            if ($data['creative_type'] == 1) {
                // Generate Creative Hash
                $uniqid = uniqid(time());
                $creative_hash = md5($uniqid);
                $file_extension = strtolower(substr(strrchr($_FILES['creative_file']['name'], "."), 1));
                // Case: Remote Creative Server (FTP)
                if (getconfig_var('default_creative_server') > 1) {
                    list($width, $height, $type, $attr) = getimagesize($_FILES['creative_file']['tmp_name']);
                    if ($height != $data['custom_creative_height'] or $width != $data['custom_creative_width'] or empty($file_extension)) {
                        global $errormessage;
                        $errormessage = 'The image you uploaded does not appear to be in the right dimensions. Please upload a valid image sized ' . $data['custom_creative_width'] . 'x' . $data['custom_creative_height'] . '';
                        global $editdata;
                        $editdata = $data;
                        return false;
                    }
                    $creative_server_detail = get_creativeserver_detail(getconfig_var('default_creative_server'));
                    if ($creative_server_detail['entry_id'] < 1) {
                        global $errormessage;
                        $errormessage = 'The default creative server does not seem to exist. Please change your creative server in your mAdserve control panel under Configuration>Creative Servers';
                        global $editdata;
                        $editdata = $data;
                        return false;
                    }
                    // Attempt: Upload
                    include MAD_PATH . '/modules/ftp/ftp.class.php';
                    try {
                        $ftp = new Ftp();
                        $ftp->connect($creative_server_detail['remote_host']);
                        $ftp->login($creative_server_detail[remote_user], $creative_server_detail[remote_password]);
                        $ftp->put($creative_server_detail[remote_directory] . $creative_hash . '.' . $file_extension, $_FILES['creative_file']['tmp_name'], FTP_BINARY);
                    } catch (FtpException $e) {
                        global $errormessage;
                        $errormessage = 'FTP Client was unable to upload creative to remote server. Error given: ' . $e->getMessage() . '';
                        global $editdata;
                        $editdata = $data;
                        return false;
                    }
                    // End: Upload
                }
                // End Case: Remote Creative Server (FTP)
                // Case: Local Creative Server
                if (getconfig_var('default_creative_server') == 1) {
                    include MAD_PATH . '/modules/upload/class.upload.php';
                    $handle = new Upload($_FILES['creative_file']);
                    $handle->allowed = array('image/*');
                    $handle->file_new_name_body = $creative_hash;
                    if ($handle->uploaded) {
                        $image_width = $handle->image_src_x;
                        $image_height = $handle->image_src_y;
                        if (!empty($image_width) && !empty($image_height) && ($image_height != $data['custom_creative_height'] or $image_width != $data['custom_creative_width'])) {
                            global $errormessage;
                            $errormessage = 'The image you uploaded does not appear to be in the right dimensions. Please upload an image sized ' . $data['custom_creative_width'] . 'x' . $data['custom_creative_height'] . '';
                            global $editdata;
                            $editdata = $data;
                            return false;
                        }
                        $handle->Process(MAD_PATH . MAD_CREATIVE_DIR);
                        if ($handle->processed) {
                            // OK
                        } else {
                            global $errormessage;
                            $errormessage = 'Creative could not be uploaded. Please check if your creative directory is writeable (' . MAD_CREATIVE_DIR . ') and that you have uploaded a valid image file.';
                            global $editdata;
                            $editdata = $data;
                            return false;
                        }
                    } else {
                        // Not OK
                        global $errormessage;
                        $errormessage = 'Creative could not be uploaded. Please check if your creative directory is writeable (' . MAD_CREATIVE_DIR . ') and that you have uploaded a valid image file.';
                        global $editdata;
                        $editdata = $data;
                        return false;
                    }
                }
                // End Case: Local Creative Sercer
            }
            // END CREATIVE UPLOAD
        }
        $creation_timestamp = time();
        /* Date Stuff */
        if ($data['start_date_type'] == 1) {
            $start_date_array['year'] = date("Y");
            $start_date_array['day'] = date("d");
            $start_date_array['month'] = date("m");
        }
        if ($data['end_date_type'] == 1) {
            $end_date_array['year'] = '2090';
            $end_date_array['day'] = '12';
            $end_date_array['month'] = '12';
        }
        if ($data['start_date_type'] == 2) {
            $start_date = explode('/', $data['startdate_value']);
            $start_date_array['year'] = $start_date[2];
            $start_date_array['day'] = $start_date[1];
            $start_date_array['month'] = $start_date[0];
            $start_date_array['unix'] = strtotime("{$start_date_array['year']}-{$start_date_array['month']}-{$start_date_array['day']}");
        }
        if ($data['end_date_type'] == 2) {
            $end_date = explode('/', $data['enddate_value']);
            $end_date_array['year'] = $end_date[2];
            $end_date_array['day'] = $end_date[1];
            $end_date_array['month'] = $end_date[0];
            $end_date_array['unix'] = strtotime("{$end_date_array['year']}-{$end_date_array['month']}-{$end_date_array['day']}");
        }
        $data['startdate_value'] = '' . $start_date_array['year'] . '-' . $start_date_array['month'] . '-' . $start_date_array['day'] . '';
        $data['enddate_value'] = '' . $end_date_array['year'] . '-' . $end_date_array['month'] . '-' . $end_date_array['day'] . '';
        global $maindb;
        if (!isset($data['target_iphone'])) {
            $data['target_iphone'] = '';
        }
        if (!isset($data['target_ipod'])) {
            $data['target_ipod'] = '';
        }
        if (!isset($data['target_ipad'])) {
            $data['target_ipad'] = '';
        }
        if (!isset($data['target_android'])) {
            $data['target_android'] = '';
        }
        if (!isset($data['target_other'])) {
            $data['target_other'] = '';
        }
        if (!isset($data['ios_version_min'])) {
            $data['ios_version_min'] = '';
        }
        if (!isset($data['ios_version_max'])) {
            $data['ios_version_max'] = '';
        }
        if (!isset($data['android_version_min'])) {
            $data['android_version_min'] = '';
        }
        if (!isset($data['android_version_max'])) {
            $data['android_version_max'] = '';
        }
        $data['campaign_type'] = sanitize($data['campaign_type']);
        $data['campaign_name'] = sanitize($data['campaign_name']);
        $data['campaign_desc'] = sanitize($data['campaign_desc']);
        $data['startdate_value'] = sanitize($data['startdate_value']);
        $data['enddate_value'] = sanitize($data['enddate_value']);
        $data['campaign_networkid'] = sanitize($data['campaign_networkid']);
        $data['campaign_priority'] = sanitize($data['campaign_priority']);
        $data['target_iphone'] = sanitize($data['target_iphone']);
        $data['target_ipod'] = sanitize($data['target_ipod']);
        $data['target_ipad'] = sanitize($data['target_ipad']);
        $data['target_android'] = sanitize($data['target_android']);
        $data['target_other'] = sanitize($data['target_other']);
        $data['ios_version_min'] = sanitize($data['ios_version_min']);
        $data['ios_version_max'] = sanitize($data['ios_version_max']);
        $data['android_version_min'] = sanitize($data['android_version_min']);
        $data['android_version_max'] = sanitize($data['android_version_max']);
        $data['geo_targeting'] = sanitize($data['geo_targeting']);
        $data['publication_targeting'] = sanitize($data['publication_targeting']);
        $data['channel_targeting'] = sanitize($data['channel_targeting']);
        $data['device_targeting'] = sanitize($data['device_targeting']);
        // Insert Campaign into DB
        mysql_query("INSERT INTO md_campaigns (campaign_owner, campaign_status, campaign_type, campaign_name, campaign_desc, campaign_start, campaign_end, campaign_creationdate, campaign_networkid, campaign_priority, target_iphone, target_ipod, target_ipad, target_android, target_other, ios_version_min, ios_version_max, android_version_min, android_version_max, country_target, publication_target, channel_target, device_target)\nVALUES ('{$user_detail['user_id']}', '1', '{$data['campaign_type']}', '{$data['campaign_name']}', '{$data['campaign_desc']}', '{$data['startdate_value']}', '{$data['enddate_value']}', '{$creation_timestamp}', '{$data['campaign_networkid']}', '{$data['campaign_priority']}', '{$data['target_iphone']}', '{$data['target_ipod']}', '{$data['target_ipad']}', '{$data['target_android']}', '{$data['target_other']}', '{$data['ios_version_min']}', '{$data['ios_version_max']}', '{$data['android_version_min']}', '{$data['android_version_max']}', '{$data['geo_targeting']}', '{$data['publication_targeting']}', {$data['channel_targeting']}, '{$data['device_targeting']}')", $maindb);
        global $created_campaign_id;
        $created_campaign_id = mysql_insert_id($maindb);
        // END: Insert Campaign into DB
        if ($data['campaign_type'] != 'network') {
            if ($data['creative_type'] == 1) {
                $creative_server = getconfig_var('default_creative_server');
            }
            // Insert Ad Unit into DB
            if (!isset($creative_server)) {
                $creative_server = '';
            }
            if (!isset($creative_hash)) {
                $creative_hash = '';
            }
            if (!isset($file_extension)) {
                $file_extension = '';
            }
            if (!isset($data['adv_mraid'])) {
                $data['adv_mraid'] = '';
            }
            $data['creative_type'] = sanitize($data['creative_type']);
            $data['click_url'] = sanitize($data['click_url']);
            $data['html_body'] = sanitize($data['html_body']);
            $data['creative_url'] = sanitize($data['creative_url']);
            $data['tracking_pixel'] = sanitize($data['tracking_pixel']);
            $data['adv_name'] = sanitize($data['adv_name']);
            $data['custom_creative_height'] = sanitize($data['custom_creative_height']);
            $data['custom_creative_width'] = sanitize($data['custom_creative_width']);
            $data['adv_mraid'] = sanitize($data['adv_mraid']);
            mysql_query("INSERT INTO md_ad_units (campaign_id, unit_hash, adv_type, adv_status, adv_click_url, adv_click_opentype, adv_chtml, adv_bannerurl, adv_impression_tracking_url, adv_name, adv_clickthrough_type, adv_creative_extension, adv_height, adv_width, creativeserver_id, adv_mraid)\nVALUES ('{$created_campaign_id}', '{$creative_hash}', '{$data['creative_type']}', '1', '{$data['click_url']}', '', '{$data['html_body']}', '{$data['creative_url']}', '{$data['tracking_pixel']}', '{$data['adv_name']}', '', '{$file_extension}', '{$data['custom_creative_height']}', '{$data['custom_creative_width']}', '{$creative_server}', '{$data['adv_mraid']}')", $maindb);
            global $created_adunit_id;
            $created_adunit_id = mysql_insert_id($maindb);
            // END: Insert Ad Unit into DB
        }
        // Extra Targeting Variables
        // Country
        if ($data['geo_targeting'] == 2) {
            $separate_countries = explode(',', $data['as_values_1']);
            foreach ($separate_countries as $country_tag) {
                if (!empty($country_tag)) {
                    // Add Country
                    add_campaign_targeting($created_campaign_id, 'geo', $country_tag);
                }
            }
        }
        //End Country
        // Channel
        if ($data['channel_targeting'] == 2 && is_array($data['channel_select'])) {
            foreach ($data['channel_select'] as $channel_id) {
                add_campaign_targeting($created_campaign_id, 'channel', $channel_id);
            }
        }
        // End Channel
        // Placement
        if ($data['publication_targeting'] == 2 && is_array($data['placement_select'])) {
            foreach ($data['placement_select'] as $placement_id) {
                add_campaign_targeting($created_campaign_id, 'placement', $placement_id);
            }
        }
        // End Placement
        // End: Extra Targeting Variables
        if (!isset($data['cap_type'])) {
            $data['cap_type'] = '';
        }
        if (!isset($data['total_amount'])) {
            $data['total_amount'] = '';
        }
        // Add Campaign Limit
        mysql_query("INSERT INTO md_campaign_limit (campaign_id, cap_type, total_amount, total_amount_left)\nVALUES ('{$created_campaign_id}', '{$data['cap_type']}', '{$data['total_amount']}', '{$data['total_amount']}')", $maindb);
        // END: Add Campaign Limit
        return true;
    }
    if ($type == 'placement') {
        global $maindb;
        if (!isset($data['mobfox_min_cpc_active'])) {
            $data['mobfox_min_cpc_active'] = 0;
        }
        if (!isset($data['mobfox_backfill_active'])) {
            $data['mobfox_backfill_active'] = 0;
        }
        if (!isset($data['zone_height'])) {
            $data['zone_height'] = '';
        }
        if (!isset($data['zone_width'])) {
            $data['zone_width'] = '';
        }
        if (!is_numeric($detail)) {
            global $errormessage;
            $errormessage = 'Please select a Publication to add this zone to.';
            global $editdata;
            $editdata = $data;
            return false;
        }
        if (!is_numeric($data['zone_refresh']) or empty($data['zone_name']) or $data['zone_size'] == '10' && (!is_numeric($data['custom_zone_width']) or !is_numeric($data['custom_zone_height'])) or empty($data['zone_type']) or $data['zone_type'] == 'banner' && !is_numeric($data['zone_size'])) {
            global $errormessage;
            $errormessage = 'Please fill out all required fields.';
            global $editdata;
            $editdata = $data;
            return false;
        }
        if ($data['mobfox_min_cpc_active'] == 1 && (!is_numeric($data['min_cpc']) or !is_numeric($data['min_cpm']) or $data['min_cpm'] > 5 or $data['min_cpc'] > 0.2)) {
            global $errormessage;
            $errormessage = 'Invalid minimum CPC/CPM values entered.';
            global $editdata;
            $editdata = $data;
            return false;
        }
        $publication_detail = get_publication_detail($detail);
        if ($publication_detail['inv_type'] == 3 && $data['zone_type'] == 'interstitial') {
            global $errormessage;
            $errormessage = 'Full Page Interstitials are supported only inside iOS and Android applications.';
            global $editdata;
            $editdata = $data;
            return false;
        }
        $uniqid = uniqid($data['zone_name']);
        $new_placement_hash = md5($uniqid);
        if ($data['zone_size'] == 1) {
            $data['zone_width'] = 320;
            $data['zone_height'] = 50;
        }
        if ($data['zone_size'] == 2) {
            $data['zone_width'] = 300;
            $data['zone_height'] = 250;
        }
        if ($data['zone_size'] == 3) {
            $data['zone_width'] = 728;
            $data['zone_height'] = 90;
        }
        if ($data['zone_size'] == 4) {
            $data['zone_width'] = 160;
            $data['zone_height'] = 600;
        }
        $data['zone_name'] = sanitize($data['zone_name']);
        $data['zone_type'] = sanitize($data['zone_type']);
        $data['zone_width'] = sanitize($data['zone_width']);
        $data['zone_height'] = sanitize($data['zone_height']);
        $data['zone_refresh'] = sanitize($data['zone_refresh']);
        $data['zone_channel'] = sanitize($data['zone_channel']);
        $data['zone_description'] = sanitize($data['zone_description']);
        $data['mobfox_backfill_active'] = sanitize($data['mobfox_backfill_active']);
        $data['mobfox_min_cpc_active'] = sanitize($data['mobfox_min_cpc_active']);
        $data['min_cpc'] = sanitize($data['min_cpc']);
        $data['min_cpm'] = sanitize($data['min_cpm']);
        $data['backfill_alt_1'] = sanitize($data['backfill_alt_1']);
        $data['backfill_alt_2'] = sanitize($data['backfill_alt_2']);
        $data['backfill_alt_3'] = sanitize($data['backfill_alt_3']);
        mysql_query("INSERT INTO md_zones (publication_id, zone_hash, zone_name, zone_type, zone_width, zone_height, zone_refresh, zone_channel, zone_description, mobfox_backfill_active, mobfox_min_cpc_active, min_cpc, min_cpm, backfill_alt_1, backfill_alt_2, backfill_alt_3)\nVALUES ('{$detail}', '{$new_placement_hash}', '{$data['zone_name']}', '{$data['zone_type']}', '{$data['zone_width']}', '{$data['zone_height']}', '{$data['zone_refresh']}', '{$data['zone_channel']}', '{$data['zone_description']}', '{$data['mobfox_backfill_active']}', '{$data['mobfox_min_cpc_active']}', '{$data['min_cpc']}', '{$data['min_cpm']}', '{$data['backfill_alt_1']}', '{$data['backfill_alt_2']}', '{$data['backfill_alt_3']}')", $maindb);
        global $created_zone_id;
        $created_zone_id = mysql_insert_id($maindb);
        mf_add_publication_layer($created_zone_id, 1);
        return true;
    }
    if ($type == 'publication') {
        global $maindb;
        if (!isset($data['mobfox_min_cpc_active'])) {
            $data['mobfox_min_cpc_active'] = 0;
        }
        if (!isset($data['mobfox_backfill_active'])) {
            $data['mobfox_backfill_active'] = 0;
        }
        if (!isset($data['zone_height'])) {
            $data['zone_height'] = '';
        }
        if (!isset($data['zone_width'])) {
            $data['zone_width'] = '';
        }
        if (empty($data['inv_name']) or !is_numeric($data['inv_type']) or empty($data['inv_address']) or !is_numeric($data['inv_defaultchannel']) or !is_numeric($data['zone_refresh']) or empty($data['zone_name']) or $data['zone_size'] == '10' && (!is_numeric($data['custom_zone_width']) or !is_numeric($data['custom_zone_height'])) or empty($data['zone_type']) or $data['zone_type'] == 'banner' && !is_numeric($data['zone_size'])) {
            global $errormessage;
            $errormessage = 'Please fill out all required fields.';
            global $editdata;
            $editdata = $data;
            return false;
        }
        if ($data['mobfox_min_cpc_active'] == 1 && (!is_numeric($data['min_cpc']) or !is_numeric($data['min_cpm']) or $data['min_cpm'] > 5 or $data['min_cpc'] > 0.2)) {
            global $errormessage;
            $errormessage = 'Invalid minimum CPC/CPM values entered.';
            global $editdata;
            $editdata = $data;
            return false;
        }
        if ($data['inv_type'] == 3 && $data['zone_type'] == 'interstitial') {
            global $errormessage;
            $errormessage = 'Full Page Interstitials are supported only inside iOS and Android applications.';
            global $editdata;
            $editdata = $data;
            return false;
        }
        $data['inv_type'] = sanitize($data['inv_type']);
        $data['inv_name'] = sanitize($data['inv_name']);
        $data['inv_description'] = sanitize($data['inv_description']);
        $data['inv_address'] = sanitize($data['inv_address']);
        $data['inv_defaultchannel'] = sanitize($data['inv_defaultchannel']);
        mysql_query("INSERT INTO md_publications (inv_status, inv_type, inv_name, inv_description, inv_address, inv_defaultchannel, creator_id)\nVALUES (1, '{$data['inv_type']}', '{$data['inv_name']}', '{$data['inv_description']}', '{$data['inv_address']}', '{$data['inv_defaultchannel']}', '{$user_detail['user_id']}')", $maindb);
        $new_publication_id = mysql_insert_id($maindb);
        if (do_create('placement', $data, $new_publication_id)) {
            return true;
        }
    }
}
Ejemplo n.º 14
0
function file_remote_upload($filename)
{
    global $_W;
    if (empty($_W['setting']['remote']['type'])) {
        return false;
    }
    if ($_W['setting']['remote']['type'] == '1') {
        require IA_ROOT . '/framework/library/ftp/ftp.php';
        $remoteConfig = array('hostname' => $_W['setting']['remote']['ftp']['host'], 'username' => $_W['setting']['remote']['ftp']['username'], 'password' => $_W['setting']['remote']['ftp']['password'], 'port' => $_W['setting']['remote']['ftp']['port'], 'ssl' => $_W['setting']['remote']['ftp']['ssl'], 'passive' => $_W['setting']['remote']['ftp']['pasv'], 'timeout' => $_W['setting']['remote']['ftp']['timeout']);
        $ftp = new Ftp($remoteConfig);
        if (true === $ftp->connect()) {
            $pathinfo = pathinfo($filename);
            $dirs = explode('/', $_W['setting']['remote']['ftp']['dir'] . '/' . $pathinfo['dirname']);
            $dir = '';
            foreach ($dirs as $row) {
                if (!empty($row)) {
                    $dir .= '/' . $row;
                    $ftp->mkdir($dir);
                }
            }
            $desfile = $_W['setting']['remote']['ftp']['dir'] . '/' . $filename;
            if ($ftp->upload(ATTACHMENT_ROOT . '/' . $filename, $desfile)) {
                return true;
            } else {
                return error(1, '远程附件上传失败,请检查配置并重新上传');
            }
        } else {
            return error(1, '远程附件上传失败,请检查配置并重新上传');
        }
    } elseif ($_W['setting']['remote']['type'] == '2') {
        require IA_ROOT . '/framework/library/alioss/sdk.class.php';
        $oss = new ALIOSS($_W['setting']['remote']['alioss']['key'], $_W['setting']['remote']['alioss']['secret'], $_W['setting']['remote']['alioss']['url'] . '.aliyuncs.com');
        $options = array(ALIOSS::OSS_FILE_UPLOAD => ATTACHMENT_ROOT . '/' . $filename, ALIOSS::OSS_PART_SIZE => 5242880);
        $response = $oss->create_mpu_object($_W['setting']['remote']['alioss']['bucket'], $filename, $options);
        if ($response->status == 200) {
            return true;
        } else {
            return error(1, '远程附件上传失败,请检查配置并重新上传');
        }
    }
}
Ejemplo n.º 15
0
 /**
  * 通过FTP上传图片
  * FTP上传不检查文件是否已存在(存在会返回FALSE)
  * @param string $uploadformname 需要上传的表单名,$_FILES中
  * @return boolean
  */
 public function ftpUpload($uploadformname)
 {
     if (empty($this->_ftpconf)) {
         self::$message = '未设置FTP登录信息';
         return false;
     }
     //文件检查
     if (!$this->check($uploadformname)) {
         return false;
     }
     //要上传的图片缓存信息
     $upfile = $_FILES[$uploadformname];
     //图像类型
     $imgtype = exif_imagetype($upfile['tmp_name']);
     //图片尺寸信息
     $size = getimagesize($upfile['tmp_name']);
     $ftp = new Ftp();
     $constatus = $ftp->connect($this->_ftpconf);
     if (!$constatus) {
         self::$message = '上传服务器连接失败';
         return false;
     }
     //尝试创建目录,不返回状态,有可能目录已存在
     $ftp->mkdir($this->_dir);
     $upsatus = $ftp->upload($upfile['tmp_name'], $this->_dir . $this->_savename, '');
     if (!$upsatus) {
         self::$message = '上传失败,服务器繁忙';
         return false;
     }
     //返回图片属性
     self::$picinfo = pathinfo($this->_dir . $this->_savename);
     self::$picinfo['width'] = $size[0];
     self::$picinfo['height'] = $size[1];
     self::$picinfo['size'] = $upfile['size'];
     self::$message = '成功';
     return true;
 }
Ejemplo n.º 16
0
 /**
  * [set_product_images_oxid description]
  * @param [type] $product [description]
  */
 private function set_product_images_oxid($product)
 {
     global $oxid, $selectline;
     $product->images = $selectline['db']->get_results("SELECT * FROM " . $selectline['table_product_img'] . " WHERE [Blobkey] = 'AR" . $product->Artikelnummer . "'");
     if ($product->images) {
         $i = 1;
         $ftp = new Ftp();
         $ftp->connect($oxid['ftp_host']);
         $ftp->login($oxid['ftp_user'], $oxid['ftp_password']);
         foreach ($product->images as $image) {
             $img = WideImage::load($image->Bild);
             if ($i > 1) {
                 $filename = $product->ART_ID . '_' . $i . '.jpg';
             } else {
                 $filename = $product->ART_ID . '.jpg';
             }
             $img->saveToFile(ABSPATH . '/images/' . $filename);
             $ftp->put($oxid['img_path'] . '/master/product/' . $i . '/' . $filename, ABSPATH . '/images/' . $filename, FTP_BINARY);
             @unlink(ABSPATH . '/images/' . $filename);
             $oxid['db']->query($this->format_update_query($oxid['table_products'], array('OXPIC1' => $filename), array('OXID' => $product->ART_ID)));
             $i++;
         }
         $ftp->close();
     }
 }
Ejemplo n.º 17
0
// www.xtac.net
$container['template'] = function ($c) {
    $tpl = new \Template_();
    $tpl->skin = 'bootstrap';
    return $tpl;
};
// logger
$container['logger'] = function ($c) {
    $logger = new Kaiser\Manager\LogManager(__DIR__ . '/../logs');
    return $logger;
};
// session
$container['session'] = function ($c) {
    $session = new Kaiser\Session\FileSession(__DIR__ . '/../tmp');
    $session->start_session();
    return $session;
};
// ftp
$container['ftp'] = function ($c) {
    $ftp = new \Ftp();
    // Opens an FTP connection to the specified host
    $ftp->connect($c['config']->get('ftp.host'));
    if (!empty($c['config']->get('ftp.user')) && !empty($c['config']->get('ftp.pass'))) {
        // Login with username and password
        $ftp->login($c['config']->get('ftp.user'), $c['config']->get('ftp.pass'));
    } elseif (!empty($_SESSION['user']['username']) && !empty($_SESSION['user']['password'])) {
        $ftp->login($_SESSION['user']['username'], $_SESSION['user']['password']);
    }
    $ftp->pasv($c['config']->get('ftp.passive'));
    return $ftp;
};
Ejemplo n.º 18
0
 /**
  * @expectedException RuntimeException
  */
 public function testPassiveFailSsl()
 {
     $adapter = new Ftp(array('host' => 'pasv.fail', 'ssl' => true, 'root' => 'somewhere'));
     $adapter->connect();
 }
Ejemplo n.º 19
0
function file_remote_delete($file)
{
    global $_W;
    if (empty($file)) {
        return true;
    }
    if ($_W['setting']['remote']['type'] == '1') {
        require_once IA_ROOT . '/framework/library/ftp/ftp.php';
        $ftp_config = array('hostname' => $_W['setting']['remote']['ftp']['host'], 'username' => $_W['setting']['remote']['ftp']['username'], 'password' => $_W['setting']['remote']['ftp']['password'], 'port' => $_W['setting']['remote']['ftp']['port'], 'ssl' => $_W['setting']['remote']['ftp']['ssl'], 'passive' => $_W['setting']['remote']['ftp']['pasv'], 'timeout' => $_W['setting']['remote']['ftp']['timeout'], 'rootdir' => $_W['setting']['remote']['ftp']['dir']);
        $ftp = new Ftp($ftp_config);
        if (true === $ftp->connect()) {
            if ($ftp->delete_file($file)) {
                return true;
            } else {
                return error(1, '删除附件失败,请检查配置并重新删除');
            }
        } else {
            return error(1, '删除附件失败,请检查配置并重新删除');
        }
    } elseif ($_W['setting']['remote']['type'] == '2') {
        require_once IA_ROOT . '/framework/library/alioss/sdk.class.php';
        $oss = new ALIOSS($_W['setting']['remote']['alioss']['key'], $_W['setting']['remote']['alioss']['secret'], $_W['setting']['remote']['alioss']['ossurl']);
        $response = $oss->delete_object($_W['setting']['remote']['alioss']['bucket'], $file);
        if ($response->status == 204) {
            return true;
        } else {
            return error(1, '删除oss远程文件失败');
        }
    } elseif ($_W['setting']['remote']['type'] == '3') {
        require_once IA_ROOT . '/framework/library/qiniu/autoload.php';
        $auth = new Qiniu\Auth($_W['setting']['remote']['qiniu']['accesskey'], $_W['setting']['remote']['qiniu']['secretkey']);
        $bucketMgr = new Qiniu\Storage\BucketManager($auth);
        $error = $bucketMgr->delete($_W['setting']['remote']['qiniu']['bucket'], $file);
        if ($error instanceof Qiniu\Http\Error) {
            if ($error->code() == 612) {
                return true;
            }
            return error(1, '删除七牛远程文件失败');
        } else {
            return true;
        }
    }
    return true;
}
Ejemplo n.º 20
0
 /**
  * ftp上传
  * @param $file_path:本地文件的路径
  * @param $savename:文件名 
  * @return 1;上传成功<br>
  *         0;上传失败
  */
 private function ftp_upload($ftp_file_path, $local_file_path, $savename, $type)
 {
     import("@.ORG.Ftp");
     $ftp = new Ftp();
     $conn = $ftp->connect('w1.weimg.cn', 'images', 'images580230', $port = '21', $pasv = false, $ssl = false, $timeout = 30);
     $ftp->mkdir($ftp_file_path);
     $res = $ftp->put($ftp_file_path . $savename, $local_file_path . $savename);
     if ($type == 4) {
         $ftp->put($ftp_file_path . 's_' . $savename, $local_file_path . 's_' . $savename);
         unlink('./Public/upload/s_' . $savename);
     }
     $ftp->close();
     unlink('./Public/upload/' . $savename);
     if (!$res) {
         return 0;
     } else {
         return 1;
     }
 }
Ejemplo n.º 21
0
<?php

require_once 'ftp.class.php';
try {
    $ftp = new Ftp();
    // Opens an FTP connection to the specified host
    $ftp->connect('ftp.ed.ac.uk');
    // Login with username and password
    $ftp->login('anonymous', '*****@*****.**');
    // Download file 'README' to local temporary file
    $temp = tmpfile();
    $ftp->fget($temp, 'README', Ftp::ASCII);
    // echo file
    echo '<pre>';
    fseek($temp, 0);
    fpassthru($temp);
} catch (FtpException $e) {
    echo 'Error: ', $e->getMessage();
}
Ejemplo n.º 22
0
function file_remote_delete($file)
{
    global $_W;
    if (empty($file)) {
        return true;
    }
    if ($_W['setting']['remote']['type'] == '1') {
        require IA_ROOT . '/framework/library/ftp/ftp.php';
        $ftp_config = array('hostname' => $_W['setting']['remote']['ftp']['host'], 'username' => $_W['setting']['remote']['ftp']['username'], 'password' => $_W['setting']['remote']['ftp']['password'], 'port' => $_W['setting']['remote']['ftp']['port'], 'ssl' => $_W['setting']['remote']['ftp']['ssl'], 'passive' => $_W['setting']['remote']['ftp']['pasv'], 'timeout' => $_W['setting']['remote']['ftp']['timeout'], 'rootdir' => $_W['setting']['remote']['ftp']['dir']);
        $ftp = new Ftp($ftp_config);
        if (true === $ftp->connect()) {
            if ($ftp->delete_file($file)) {
                return true;
            } else {
                return error(1, '删除附件失败,请检查配置并重新删除');
            }
        } else {
            return error(1, '删除附件失败,请检查配置并重新删除');
        }
    } elseif ($_W['setting']['remote']['type'] == '2') {
        require IA_ROOT . '/framework/library/alioss/sdk.class.php';
        $oss = new ALIOSS($_W['setting']['remote']['alioss']['key'], $_W['setting']['remote']['alioss']['secret'], $_W['setting']['remote']['alioss']['ossurl']);
        $response = $oss->delete_object($_W['setting']['remote']['alioss']['bucket'], $file);
        if ($response->status == 204) {
            return true;
        } else {
            return error(1, '删除oss远程文件失败');
        }
    }
    return true;
}
Ejemplo n.º 23
0
<?php

/**
 * [WeEngine System] Copyright (c) 2014 WE7.CC
 * WeEngine is NOT a free software, it under the license terms, visited http://www.we7.cc/ for more details.
 */
defined('IN_IA') or exit('Access Denied');
set_time_limit(0);
if ($do == 'ftp') {
    require IA_ROOT . '/framework/library/ftp/ftp.php';
    $ftp_config = array('hostname' => trim($_GPC['host']), 'username' => trim($_GPC['username']), 'password' => trim($_GPC['password']), 'port' => intval($_GPC['port']), 'ssl' => trim($_GPC['ssl']), 'passive' => trim($_GPC['pasv']), 'timeout' => intval($_GPC['overtime']), 'rootdir' => trim($_GPC['dir']));
    $url = trim($_GPC['url']);
    $filename = 'MicroEngine.ico';
    $ftp = new Ftp($ftp_config);
    if (true === $ftp->connect()) {
        if ($ftp->upload(ATTACHMENT_ROOT . 'images/global/' . $filename, $filename)) {
            load()->func('communication');
            $response = ihttp_get($url . '/' . $filename);
            if (is_error($response)) {
                message(error(-1, '配置失败,FTP远程访问url错误'), '', 'ajax');
            }
            if (intval($response['code']) != 200) {
                message(error(-1, '配置失败,FTP远程访问url错误'), '', 'ajax');
            }
            $image = getimagesizefromstring($response['content']);
            if (!empty($image) && strexists($image['mime'], 'image')) {
                message(error(0, '配置成功'), '', 'ajax');
            } else {
                message(error(-1, '配置失败,FTP远程访问url错误'), '', 'ajax');
            }
        } else {
Ejemplo n.º 24
0
/**
 * Copies files using FTP access
 *
 * @param string $source Absolute path (non-ftp) to source dir/file
 * @param string $destination Absolute path (non-ftp) to destination dir/file
 * @param array $ftp_access
 *      array(
 *          'hostname',
 *          'username',
 *          'password',
 *          'directory'
 *      )
 * @return bool true if all files were copied or (string) Error message
 */
function fn_copy_by_ftp($source, $destination, $ftp_access)
{
    try {
        $ftp = new Ftp();
        $ftp->connect($ftp_access['hostname']);
        $ftp->login($ftp_access['username'], $ftp_access['password']);
        $ftp->chdir($ftp_access['directory']);
        $files = $ftp->nlist('');
        if (!empty($files) && in_array('config.php', $files)) {
            $ftp_destination = str_replace(Registry::get('config.dir.root'), '', $destination);
            if (is_file($source)) {
                // File
                try {
                    $file = ltrim($ftp_destination, '/');
                    $ftp->put($file, $source, FTP_BINARY);
                } catch (FtpException $e) {
                    throw new FtpException('ftp_access_denied' . ':' . $e->getMessage());
                }
            } else {
                // Dir
                $ftp->chdir($ftp_access['directory'] . $ftp_destination);
                $struct = fn_get_dir_contents($source, false, true, '', '', true);
                foreach ($struct as $file) {
                    $dir = dirname($file);
                    if (!$ftp->isDir($dir)) {
                        try {
                            $ftp->mkDirRecursive($dir);
                        } catch (FtpException $e) {
                            throw new FtpException('ftp_access_denied' . ':' . $e->getMessage());
                        }
                    }
                    try {
                        $ftp->put($file, $source . $file, FTP_BINARY);
                    } catch (FtpException $e) {
                        throw new FtpException('ftp_access_denied' . ':' . $e->getMessage());
                    }
                }
            }
            return true;
        } else {
            throw new FtpException('ftp_directory_is_incorrect');
        }
    } catch (FtpException $e) {
        return __('invalid_ftp_access') . ': ' . $e->getMessage();
    }
    return false;
}
Ejemplo n.º 25
0
 /**
  * Runs the FTP deploy task.
  *
  * @return Result The result of the task.
  */
 public function run()
 {
     $ftp = new \Ftp();
     // connect to the server
     try {
         if ($this->useSSL) {
             $ftp->sslConnect($this->host);
         } else {
             $ftp->connect($this->host);
         }
         $ftp->login($this->user, $this->password);
         // create the target directory if it does not exist
         $ftp->chdir('/');
         if (!$ftp->fileExists($this->targetDirectory)) {
             $this->printTaskInfo('Creating directory: ' . $this->targetDirectory);
             $ftp->mkDirRecursive($this->targetDirectory);
         }
         // get files from git if enabled
         if ($this->gitDiff) {
             $this->files($this->getGitDiff($ftp));
         }
         // scan and index files in finder
         $this->printTaskInfo('Scanning files to upload...');
         // add discrete files
         $this->finder->append(new \ArrayIterator($this->files));
         // directories first
         $this->finder->sortByType();
         // display summary before deploying
         $this->printTaskInfo(sprintf('Deploying %d files to "%s://%s@%s%s"...', $this->finder->count(), $this->useSSL ? 'ftps' : 'ftp', $this->user, $this->host, $this->targetDirectory));
         // upload each file, starting with directories
         foreach ($this->finder as $file) {
             $this->upload($ftp, $file);
         }
         // close the connection
         $ftp->close();
     } catch (\FtpException $e) {
         return Result::error($this, 'Error: ' . $e->getMessage());
     }
     // success!
     return Result::success($this, 'All files deployed.');
 }