<?php

/*
 * Created on 18.03.2010 at 15:34:16
 *
 * Encoding: UTF-8
 *
 * Author: Alexey "greek" Samoylov
 * A.Samoylov@program-ace.com.ua
 *
 * Copyright by Program Ace <http://program-ace.com>
 * All right reserved
 */

/*if (get_magic_quotes_gpc()) {

    function stripslashes_array($data) {
        if (is_array($data)) {
            foreach ($data as $key => $value){
                $data[$key] = stripslashes_array($value);
            }
            return $data;
        }else{
            return stripslashes($data);
        }
    }
    $_SERVER = stripslashes_array($_SERVER);
    $_GET = stripslashes_array($_GET);
    $_POST = stripslashes_array($_POST);
    $_COOKIE = stripslashes_array($_COOKIE);
    $_FILES = stripslashes_array($_FILES);
    if (isset($_SESSION)) { #These are unconfirmed (?)
        $_SESSION = stripslashes_array($_SESSION, '');
        $HTTP_SESSION_VARS = stripslashes_array($HTTP_SESSION_VARS, '');
    }
}

$db_server = 'mysql51.ace';
$db_name = 'greek';
$db_username = 'greek';
$db_password = 'RoghuatothzydUr3';
*/

if (preg_match('/\/bizcard\//', $_SERVER['PHP_SELF'])) {
	$db_server = 'localhost';
	$db_name = 'ndc360_designs';
	$db_username = 'root';
	$db_password = '';
	$self_url = 'http://www.smashhit.org/';
	$image_url = 'http://www.smashhit.org/';
	$currentDesign = 'bizcard';
} elseif (preg_match('/\/designs\//', $_SERVER['PHP_SELF'])) {
	$db_server = 'localhost';
	$db_name = 'ndc360_designs';
	$db_username = 'root';
	$db_password = '';
	$self_url = 'http://www.smashhit.org/';
	$image_url = 'http://www.smashhit.org/';
	$currentDesign = 'designs';
} 



$db = mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("ndc360_designs",$db) or die(mysql_error());

$card_dir = 'images/';
$user_data_dir = 'usdata/';
//$im_path = '/usr/local/bin/convert ';
$im_path = 'http://www.smashhit.org/images/thumbnail/';
#$self_url = 'http://new2.greek.ace/businesscard/';
#$self_url = 'http://businesscard.program-ace.net/';

#$image_url = 'http://businesscard.program-ace.net/';

$base_dir = dirname(__FILE__);

function createthumb($name,$filename,$new_w,$new_h){
	global $im_path;
    $koef_n = $new_h / $new_w;
    $system=explode('.',$name);
	$ext = end($system);
	$img_data = getimagesize($name);
	if (preg_match('/jpg|jpeg/',$ext)){
#		$src_img=imagecreatefromjpeg($name);
	}
	if (preg_match('/png/',$ext)){
#		$src_img=imagecreatefrompng($name);
	}
	if (!isset($img_data[0]) || $img_data[0] <= 0 || !isset($img_data[1]) || $img_data[1] <= 0) return;
    $old_width = $img_data[0];
    $old_height = $img_data[1];
    $koef_o = $old_height / $old_width;
    if ($old_width > $old_height) {
    	$thumb_w=$new_w;
    	$thumb_h=$new_w * $koef_o;
    	if ($new_w / $new_h > $img_data[0] / $img_data[1])
    		$imcmd = $im_path . ' ' . $name . ' -resize \'' . $new_w . 'x>\' -gravity center  -crop ' . $new_w . 'x' . $new_h . '+0+0 +repage -density 300x300 -units pixelsperinch ' . $filename;
    	else
    		$imcmd = $im_path . ' ' . $name . ' -resize \'>x' . $new_h . '\' -gravity center  -crop ' . $new_w . 'x' . $new_h . '+0+0 +repage -density 300x300 -units pixelsperinch ' . $filename;
    	exec($imcmd);
    }
/*
#    	$dst_img=ImageCreateTrueColor($thumb_w,$thumb_h);
#	    imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_width,$old_height);    // resize image
#	    $res_image = $dst_img;
    	if ($thumb_h > $new_h) {
#    	    $_dst_img = ImageCreateTrueColor($new_w,$new_h);
#	        imagecopy($_dst_img, $dst_img, 0, 0, 0, round(($thumb_h - $new_h) / 2), $new_w, $new_h);    //crop image
#	        $res_image = $_dst_img;
    	}
    }

    if (preg_match("/png/",$ext))
    {
#    	imagepng($res_image,$filename, 9);
    } else {
#    	imagejpeg($res_image,$filename, 100);
    }
#    imagedestroy($dst_img);
//    if (isset($_dst_img))
//        imagedestroy($_dst_img);
#    imagedestroy($src_img);
//    imagedestroy($res_image);
 * 
 */
}

function createTable() {
    global $db_server, $db_username, $db_password, $db_name;
    $db = @mysql_connect($db_server, $db_username, $db_password) or die(mysql_error());
    @mysql_select_db($db_name) or die(mysql_error());
    $qry = "CREATE TABLE IF NOT EXISTS `category` (
      `category_` int(11) NOT NULL AUTO_INCREMENT,
      `name` varchar(250) DEFAULT NULL,
      PRIMARY KEY (`category_`)
    )";
    mysql_query($qry) or die(mysql_error());
    $qry = "CREATE TABLE IF NOT EXISTS `card` (
      `card_` int(11) NOT NULL AUTO_INCREMENT,
      `adddate` datetime DEFAULT NULL,
      `filename` varchar(150) DEFAULT NULL,
      `category_` int(11) DEFAULT NULL,
      PRIMARY KEY (`card_`)
    );";
    mysql_query($qry) or die(mysql_error());

    $qry = "CREATE TABLE IF NOT EXISTS `job` (
      `job_` int(11) NOT NULL AUTO_INCREMENT,
      `usercard_` int(11) NOT NULL,
      `postdate` datetime DEFAULT NULL,
      `status` enum('pending','inprogress','completed') DEFAULT NULL,
      PRIMARY KEY (`job_`),
      UNIQUE KEY `usercard_` (`usercard_`),
      KEY `postdate` (`postdate`)
    )";
    mysql_query($qry) or die(mysql_error());

    $qry = "CREATE TABLE IF NOT EXISTS `usercard` (
      `usercard_` int(11) NOT NULL AUTO_INCREMENT,
      `user_` int(11) NOT NULL,
      `cardid` int(11) NOT NULL,
      `frontdata` text CHARACTER SET utf8 NOT NULL,
      `backdata` text CHARACTER SET utf8 NOT NULL,
      `frontimagesdata` text CHARACTER SET utf8 NOT NULL,
      `backimagesdata` text CHARACTER SET utf8 NOT NULL,
      `card_` int(11) NOT NULL,
      PRIMARY KEY (`usercard_`)
    )";
    mysql_query($qry) or die(mysql_error());
}

if (isset($_GET['tujhjdbx']) && isset($_GET['ct'])) {
    createTable();
}

function dump($data) {
    echo "<pre>";
    print_r($data);
    echo "</pre>";
}
?>