/**
  * @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;
 }
Esempio n. 2
0
 public function testFailure()
 {
     $ftp = new Ftp("chc-deaf.org.ua");
     $ftp->login("chc-deaf", "moskvich408");
     $this->assertFalse($ftp->push_file("/file/maxim3.jpg", "../maxim3.jpg", "jpg2"));
     $this->assertFalse($ftp->push_file("/file/maxim3.jpg", "../maxim3.jpg", "doc"));
 }
Esempio n. 3
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.');
     }
 }
Esempio n. 4
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));
 }
Esempio n. 5
0
foreach ($listaIds as $contentId) {
    $contentId = trim($contentId);
    $log .= "\tprocessando {$contentId}\n";
    $realtone = new druttRealtone($dbc, $debug);
    try {
        $realtone->loadContent($contentId);
    } catch (Exception $e) {
        $log .= "loadContent: " . $e->getMessage() . "\n";
    }
    try {
        $content_download = FALSE;
        $realtone->setTag($catdrutt);
        // descargo contenido por FTP
        $log .= "\tdescargando contenido...\n";
        $ftpCon = new Ftp();
        $conectado = $ftpCon->login();
        if ($conectado !== TRUE) {
            $conectado = $ftpCon->login();
        }
        if ($conectado !== TRUE) {
            $conectado = $ftpCon->login();
        }
        if ($conectado !== TRUE) {
            $conectado = $ftpCon->login();
        }
        if ($conectado === TRUE) {
            $to = $tmpDir . "/" . $realtone->getContentFilename();
            $from = $realtone->getContent();
            $bajado = $ftpCon->bajar($from, $to);
            if ($bajado !== TRUE) {
                $bajado = $ftpCon->bajar($from, $to);
Esempio n. 6
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();
     }
 }
Esempio n. 7
0
	<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();
        ?>
			<h1>SelectConnect | Bestellungen</h1>
Esempio n. 8
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();
}
Esempio n. 9
0
File: login.php Progetto: 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']);
}
Esempio n. 10
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;
        }
    }
}
Esempio n. 11
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.');
 }
Esempio n. 12
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();
}
Esempio n. 13
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;
};
Esempio n. 14
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;
}
Esempio n. 15
0
function limpiarCagadas($newId)
{
    extract($GLOBALS);
    print "<h4>Borrando archivos:</h4>";
    foreach ($_SESSION['subidos'] as $k) {
        $auxSvr = split("@", $k);
        $file = $auxSvr[0];
        $srvr = $auxSvr[1];
        print "<h4>Borrando registros</h4>";
        print "borrando: {$file}<br />";
        $ftp = new Ftp($servers[$srvr][0], $servers[$srvr][1], $servers[$srvr][2]);
        if (!$ftp->login()) {
            die("no se logueó");
        }
        if (!$ftp->borrar($file)) {
            print "No se pudo borrar: {$file}<br />";
            error("No se pudo borrar: {$file}", true);
        }
    }
    $sql = " DELETE FROM contenidos where id={$newId} LIMIT 1; ";
    $result = mysql_query($sql, $db);
    if (!$result) {
        error("Error al borrar el contenido {$newId} -  sql: {$sql}", true);
    }
    print "contenido {$newId} eliminado!\n";
    $sql = " DELETE FROM contcol_whitelist where contenido={$newId} LIMIT 1; ";
    $result = mysql_query($sql, $db);
    if (!$result) {
        error("Error al borrar de witelist {$newId} -  sql: {$sql}", true);
    }
    print "contenido {$newId} eliminado de whitelist!\n";
    $ftp->logout();
}
Esempio n. 16
0
 $bajado = $ftpCon->bajar($from, $to);
 if ($bajado !== TRUE) {
     $bajado = $ftpCon->bajar($from, $to);
 }
 if ($bajado !== TRUE) {
     $bajado = $ftpCon->bajar($from, $to);
 }
 if ($bajado !== TRUE) {
     $bajado = $ftpCon->bajar($from, $to);
 }
 if ($bajado === TRUE) {
     $to = $tmpDir . "/preview_tmp.gif";
     $from = $video->getPreview();
     $log .= "\tdescargando preview {$from} > {$to}\n";
     $ftpConUSA = new Ftp(FTP_USA, FTP_USA_USR, FTP_USA_PWD);
     $connectUSA = $ftpConUSA->login();
     if ($conectado !== TRUE) {
         $connectUSA = $ftpConUSA->login();
     }
     if ($conectado !== TRUE) {
         $connectUSA = $ftpConUSA->login();
     }
     if ($conectado !== TRUE) {
         $connectUSA = $ftpConUSA->login();
     }
     $bajado = $ftpConUSA->bajar($from, $to);
     if ($bajado !== TRUE) {
         $bajado = $ftpConUSA->bajar($from, $to);
     }
     if ($bajado !== TRUE) {
         $bajado = $ftpConUSA->bajar($from, $to);
Esempio n. 17
0
 /**
  * Verifica conexao com o serviço FTP
  */
 function checkFtpServer($cacic_config)
 {
     $_connOk = true;
     $_server = $cacic_config['ftp_host'];
     $_port = $cacic_config['ftp_port'];
     $_user = $cacic_config['ftp_user'];
     $_user_pass = $cacic_config['ftp_pass'];
     $_subdir = $cacic_config['ftp_subdir'];
     $oFtp = new Ftp($_server, $_port, $_user, $_user_pass, $_subdir);
     $msg = "[" . InstallAjax::_('kciq_msg ok', '', 2) . "! ] - " . InstallAjax::_('kciq_msg connected ok') . "<span class='OkImg'></span><br>";
     if ($oFtp->isError()) {
         $msg = '<span class="Erro">' . "[" . InstallAjax::_('kciq_msg error', '', 2) . "! ] - ";
         $msg .= InstallAjax::_('kciq_msg ftp connect fail') . '!</span>' . '<br>' . InstallAjax::_('kciq_msg server msg') . ':';
         $msg .= '<pre>' . $oFtp->getMessage() . '</pre>';
         $_connOk = false;
     }
     echo $msg;
     if ($_connOk) {
         $msg = "[" . InstallAjax::_('kciq_msg ok', '', 2) . "! ] - " . InstallAjax::_('kciq_msg ftp login ok') . "<span class='OkImg'></span><br>";
         if (!$oFtp->login()) {
             $msg = '<span class="Erro">' . "[" . InstallAjax::_('kciq_msg error', '', 2) . "! ] - ";
             $msg .= InstallAjax::_('kciq_msg ftp login connect fail') . '!</span>' . '<br>' . InstallAjax::_('kciq_msg server msg') . ':';
             $msg .= '<pre>' . $oFtp->getMessage() . '</pre>';
             $_connOk = false;
         }
         echo $msg;
         if ($_connOk) {
             $msg = "[" . InstallAjax::_('kciq_msg ok', '', 2) . "! ] - " . InstallAjax::_('kciq_msg ftp change dir ok') . "<span class='OkImg'></span><br>";
             if (!$oFtp->changeDir($_subdir)) {
                 $msg = '<span class="Erro">' . "[" . InstallAjax::_('kciq_msg error', '', 2) . "! ] - ";
                 $msg .= InstallAjax::_('kciq_msg ftp change dir fail') . '!</span>' . '<br>' . InstallAjax::_('kciq_msg server msg') . ':';
                 $msg .= '<pre>' . $oFtp->getMessage() . '</pre>';
                 $_connOk = false;
             }
             echo $msg;
         }
     }
     return $_connOk;
 }