function merge($part1, $part2, $part3 = null)
{
    if ($part3 == null) {
        echo "<h5>Merging " . json_encode($part1) . " and " . json_encode($part2) . " ===> Result: ";
        $result = array();
        while (count($part1) > 0 || count($part2) > 0) {
            if (count($part1) > 0 && count($part2) > 0) {
                if ($part1[0] < $part2[0]) {
                    array_push($result, array_shift($part1));
                } else {
                    array_push($result, array_shift($part2));
                }
            } else {
                if (count($part1) > 0) {
                    array_push($result, array_shift($part1));
                } else {
                    array_push($result, array_shift($part2));
                }
            }
        }
        echo json_encode($result) . "</h5>";
        return $result;
    } else {
        return merge(merge($part1, $part2), $part3);
    }
}
 public function creationConditions($conditionsDivers, $conditionsDons)
 {
     foreach ($conditionsDons as $nomCondition) {
         $donsConditionnels[] = $nomCondition->getName();
     }
     $conditions = null;
     $conditions[] = merge($conditionsDivers, $donsConditionnels);
     return $conditions;
 }
Пример #3
0
function mergesort(&$shulie, $start, $end)
{
    if ($start < $end) {
        $middle = floor(($start + $end) / 2);
        mergesort($shulie, $start, $middle);
        mergesort($shulie, $middle + 1, $end);
        merge($shulie, $start, $middle, $end);
    }
}
Пример #4
0
function get($table, $fields = "*", $other = "")
{
    if (is_array($fields)) {
        $sql = "SELECT " . merge($fields) . " FROM " . $table . " " . $other;
    } else {
        $sql = "SELECT " . $fields . " FROM " . $table . " " . $other;
    }
    //echo $sql;
    return conn()->query($sql)->fetchAll();
}
Пример #5
0
function mergesort(&$lst, $a, $b)
{
    if ($b - $a < 2) {
        return;
    }
    $half = floor(($b + $a) / 2);
    mergesort($lst, $a, $half);
    mergesort($lst, $half, $b);
    merge($lst, $a, $half, $b);
}
function mergeSort($array)
{
    if (count($array) < 2) {
        return $array;
    }
    $mid = count($array) / 2;
    echo "<h5>Splitting " . json_encode($array) . " ===> Left: " . json_encode(array_slice($array, 0, $mid)) . " Right: " . json_encode(array_slice($array, $mid));
    $right = mergeSort(array_slice($array, 0, $mid));
    $left = mergeSort(array_slice($array, $mid));
    return merge($left, $right);
}
Пример #7
0
function merge_sort($arr)
{
    if (count($arr) <= 1) {
        return $arr;
    }
    $left = array_slice($arr, 0, (int) (count($arr) / 2));
    $right = array_slice($arr, (int) (count($arr) / 2));
    $left = merge_sort($left);
    $right = merge_sort($right);
    $output = merge($left, $right);
    return $output;
}
Пример #8
0
 /**
  * Encodes a coordinate (latitude, longitude) into a GeoHash string
  *
  * @param double $latitude representing the latitude part of the coordinate set
  * @param double $longitude representing the longitude part of the coordinate set
  * @return string containing the GeoHash for the specified coordinates
  */
 public static function encode($latitude, $longitude)
 {
     // Find precision (number of decimals)
     $digits = self::_decimal($latitude, $longitude);
     // Translate coordinates to binary strings
     $latBinStr = self::_encode($latitude, -90.0, 90.0, $digits);
     $lonBinStr = self::_encode($longitude, -180.0, 180.0, $digits);
     // Merge the two binary strings
     $binStr = merge($latBinStr, $lonBinStr);
     // Calculate and return Geohash for 'binary' string
     return self::_translate($binStr);
 }
Пример #9
0
function mergeSort(array $arr)
{
    $count = count($arr);
    if ($count <= 1) {
        return $arr;
    }
    $left = array_slice($arr, 0, (int) ($count / 2));
    $right = array_slice($arr, (int) ($count / 2));
    $left = mergeSort($left);
    $right = mergeSort($right);
    return merge($left, $right);
}
Пример #10
0
function mergesort($arr)
{
    if (count($arr) == 1) {
        return $arr;
    }
    $mid = count($arr) / 2;
    $left = array_slice($arr, 0, $mid);
    $right = array_slice($arr, $mid);
    $left = mergesort($left);
    $right = mergesort($right);
    return merge($left, $right);
}
Пример #11
0
function merge_sort($array)
{
    if (count($array) == 1) {
        return $array;
    }
    $middle = (int) (count($array) / 2);
    $left = array_slice($array, 0, $middle);
    $right = array_slice($array, $middle);
    $left = merge_sort($left);
    $right = merge_sort($right);
    $return_array = merge($left, $right);
    return $return_array;
}
Пример #12
0
/**
 * The get() function returns reduced coeffs from the equation */
function get($eqn)
{
    $res = split("=", $eqn);
    if (!isset($res[1]) || isset($res[2])) {
        return False;
    }
    $left = parse($res[0]);
    $right = parse($res[1]);
    if ($left === False || $right === False) {
        return False;
    }
    return merge($left, $right);
}
Пример #13
0
/**
 * Merge two indexed arrays recursively.
 * 
 *		Usage example:
 *			{$set1 = [a => [b => c], x => y]}
 *			{$set2 = [a => [b => d]]}
 *			{$result = $set1|merge:$set2} # [a => [b => d], x => y]
 */
function merge($set1, $set2)
{
    $merged = $set1;
    if (is_array($set2) || $set2 instanceof ArrayIterator) {
        foreach ($set2 as $key => &$value) {
            if ((is_array($value) || $value instanceof ArrayIterator) && (is_array($merged[$key]) || $merged[$key] instanceof ArrayIterator)) {
                $merged[$key] = merge($merged[$key], $value);
            } elseif (isset($value) && !(is_array($merged[$key]) || $merged[$key] instanceof ArrayIterator)) {
                $merged[$key] = $value;
            }
        }
    }
    return $merged;
}
Пример #14
0
function merge_sort($array_to_sort = '')
{
    if (count($array_to_sort) == 1) {
        return $array_to_sort;
    } else {
        $sp = count($array_to_sort) / 2;
        $sp = floor($sp);
        $left = array_slice($array_to_sort, 0, $sp);
        $right = array_slice($array_to_sort, $sp);
        $left = ms($left);
        $right = ms($right);
        $result = merge($left, $right);
        return $result;
    }
}
Пример #15
0
function mergesort(&$a)
{
    $cnt = count($a);
    if ($cnt <= 1) {
        return $a;
    }
    $half = $cnt / 2;
    if ($cnt % 2 != 0) {
        $half -= 0.5;
    }
    $a1 = array_slice($a, 0, $half);
    $a2 = array_slice($a, $half, $cnt - $half);
    mergesort($a1);
    mergesort($a2);
    $a = merge($a1, $a2);
}
Пример #16
0
 private function _headers()
 {
     //  PHP mail() doesn't accept from and replyTo as parameters, so we need
     //  to add them here
     $this->headers['From'] = $this->from;
     $this->headers['Reply-To'] = merge($this->replyTo, $this->from);
     //  Everything needs to be converted to a newlined string
     $return = '';
     foreach ($this->headers as $header => $value) {
         if ($value) {
             $return .= $header . ': ' . $value . PHP_EOL;
         }
     }
     //  Since we can't do a backwards search, we'll make the string go backwards
     $return = strrev($return);
     $return = preg_replace('/' . PHP_EOL . '/', '', $return, 1);
     return strrev($return);
 }
Пример #17
0
function merger($list)
{
    $len = count($list);
    $chunks = array_chunk($list, 2);
    $chunks = sort_item($chunks);
    $container = array_chunk($chunks, 2);
    while (true) {
        foreach ($container as $k => $item) {
            if (count($item) == 1) {
                $container[$k] = $item[0];
            } else {
                $container[$k] = merge($item[0], $item[1]);
            }
        }
        if (count($container[0]) == $len) {
            break;
        }
        $container = array_chunk($container, 2);
    }
    return $container[0];
}
Пример #18
0
 /**
  * Model definition.
  */
 function define()
 {
     $this->auto_increment_start = 10000;
     // Fields.
     $this->fields = array('id', 'items', 'order', 'coupon_code', 'discounts', 'taxes', 'order_id', 'account_id', 'session_id', 'date_created', 'date_updated', 'items' => function ($cart) {
         return get("/products", array(':with' => $cart['items']));
     }, 'account' => function ($cart) {
         return get("/accounts/{$cart['account_id']}");
     }, 'shipping_methods' => function ($cart) {
         return Carts::get_shipping_methods($cart);
     }, 'taxes' => function ($cart) {
         return Carts::get_taxes($cart);
     }, 'sub_total' => function ($cart) {
         return Carts::get_sub_total($cart);
     }, 'sub_discount' => function ($cart) {
         return Carts::get_sub_total($cart, array('discount' => true));
     }, 'shipping_total' => function ($cart) {
         return Carts::get_shipping_total($cart);
     }, 'shipping_discount' => function ($cart) {
         return Carts::get_shipping_total($cart, array('discount' => true));
     }, 'tax_total' => function ($cart) {
         return Carts::get_tax_total($cart);
     }, 'discount_total' => function ($cart) {
         return Carts::get_discount_total($cart);
     }, 'grand_total' => function ($cart) {
         return Carts::get_grand_total($cart);
     }, 'credit_total' => function ($cart) {
         return Carts::get_credit_total($cart);
     }, 'billing_total' => function ($cart) {
         return Carts::get_billing_total($cart);
     }, 'product_cost' => function ($cart) {
         return Carts::get_sub_total($cart, array('cost' => true));
     }, 'quantity' => function ($cart) {
         return Carts::get_quantity($cart);
     }, 'weight' => function ($cart) {
         return Carts::get_weight($cart);
     }, 'abandoned' => function ($cart) {
         return Carts::abandoned($cart);
     });
     // Search fields.
     $this->search_fields = array('id', 'order.name', 'order.email');
     // Indexes.
     $this->indexes = array('id' => 'unique');
     // Validate.
     $this->validate = array('order', ':items' => array('required' => array('id', 'price', 'quantity')));
     // Cart item quantity limit.
     $this->item_quantity_limit = 99999999;
     // Event binds.
     $this->binds = array('GET' => function ($event) {
         $data =& $event['data'];
         // Reset cart session?
         if ($data[':reset']) {
             $data['items'] = null;
             $data['order'] = null;
             $data['discounts'] = null;
             return put("/carts/{$event['id']}", $data);
         }
     }, 'POST' => function ($event) {
         $data =& $event['data'];
         // Post item into cart (shortcut to POST.items)
         if ($event['id'] && $data['item']) {
             post("/carts/{$event['id']}/items", $data['item']);
             return get("/carts/{$event['id']}");
         }
     }, 'POST.items' => function ($event) {
         $data =& $event['data'];
         // Filter the item for update.
         $data = array_pop(Orders::get_items_for_update(array($data)));
         if ($cart = get("/carts/{$event['id']}")) {
             $product = get("/products/{$data['id']}", array('pricing' => array('roles' => $cart['account']['roles'], 'quantity' => $data['quantity'] ?: 1)));
             // Item has options?
             if ($data['options']) {
                 foreach ((array) $data['options'] as $key => $option) {
                     if (is_scalar($option)) {
                         $data['options'][$key] = $option = array('name' => $option);
                     }
                     // Matches product option?
                     if (is_array($product['options']) && is_array($product['options'][$key])) {
                         $data['options'][$key]['name'] = $option['name'] ?: $product['options'][$key]['name'];
                         $data['options'][$key]['price'] = $option['price'] ?: $product['options'][$key]['price'];
                     }
                 }
             }
             // Item variant?
             if ($product['variants']) {
                 $vid = $data['variant_id'];
                 if ($variant = $product['variants'][$vid]) {
                     $data['variant'] = $variant;
                     $data['price'] = $data['price'] ?: $variant['price'];
                 } else {
                     // Variant not found.
                     $model->error('not found', 'variant_id');
                 }
             } else {
                 $data['variant'] = null;
                 $data['variant_id'] = null;
             }
             // Prevent two of the same item in cart.
             foreach ((array) $cart['items'] as $key => $item) {
                 // Exists in cart?
                 if ($data['id'] == $item['id'] && $data['options'] == $item['options'] && $data['variant'] == $item['variant']) {
                     // Update quantity.
                     $item['quantity'] += $data['quantity'];
                     return put("{$cart}/items/{$key}", $item);
                 }
             }
         }
         // Defaults.
         $data['price'] = $data['price'] ?: $product['price'];
         $data['quantity'] = round($data['quantity'] ?: 1);
     }, 'PUT.items' => function ($event, $model) {
         $data =& $event['data'];
         // Defaults.
         if (isset($data['quantity'])) {
             $data['quantity'] = round($data['quantity'] ?: 1);
             // Upper limit on item quantity.
             if ($data['quantity'] > $model->item_quantity_limit) {
                 $data['quantity'] = $model->item_quantity_limit;
             }
         }
     }, 'PUT' => function ($event, $model) {
         $data =& $event['data'];
         // Cart already exists?
         if ($data && ($cart = get("/carts/{$event['id']}"))) {
             // Update items collection?
             if ($data['items']) {
                 $cart_items = $cart['items'];
                 foreach ((array) $data['items'] as $item_id => $item) {
                     // Update existing item quantity.
                     if (isset($item['quantity']) && $cart_items[$item_id]) {
                         $cart_items[$item_id]['quantity'] = round($item['quantity']);
                         // Upper limit on item quantity.
                         if ($cart_items[$item_id]['quantity'] > $model->item_quantity_limit) {
                             $cart_items[$item_id]['quantity'] = $model->item_quantity_limit;
                         }
                         // Check product for pricing update?
                         $product = get("/products/{$cart_items[$item_id]['id']}", array('pricing' => array('roles' => $cart['account']['roles'], 'quantity' => $cart_items[$item_id]['quantity'] ?: 1)));
                         // Update pricing?
                         if ($product['pricing']) {
                             $cart_items[$item_id]['price'] = $product['price'];
                         }
                     }
                     // Remove item?
                     if ($data['items'][$item_id]['quantity'] <= 0) {
                         unset($cart_items[$item_id]);
                     }
                 }
                 $data['items'] = $cart_items;
             }
             // Removed coupon code?
             if (isset($data['coupon_code']) && !$data['coupon_code']) {
                 // Remove coupon.
                 $data['discounts'] = $cart['discounts'];
                 unset($data['discounts']['coupon']);
             } elseif ($data['coupon_code'] && $data['coupon_code'] != $cart['discount']['coupon']['code']) {
                 $discount = get("/discounts", array('code' => $data['coupon_code'], 'is_valid' => true));
                 if ($discount === false) {
                     $model->error('already used', 'coupon_code');
                 } else {
                     if (!$discount) {
                         $model->error('invalid', 'coupon_code');
                     }
                 }
                 // Remember code.
                 $data['coupon_code'] = $discount['code'];
                 // Update items from coupon.
                 foreach ((array) $discount['rules'] as $rule) {
                     if ($rule['add'] && $rule['product_id']) {
                         // Exists in cart?
                         $exists = false;
                         foreach ((array) $cart['items'] as $item_id => $item) {
                             if ($item['id'] == $rule['product_id']) {
                                 $exists = $item_id;
                                 break;
                             }
                         }
                         // Update item quantity?
                         if ($exists) {
                             put("{$cart}/items/{$exists}", array('quantity' => $rule['quantity']));
                         } else {
                             // Post new item to cart.
                             post("{$cart}/items", array('id' => $rule['product_id'], 'quantity' => $rule['quantity']));
                         }
                     }
                 }
                 $data['discounts'] = $cart['discounts'];
                 $data['discounts']['coupon'] = $discount;
             } else {
                 // Don't update coupon code directly.
                 unset($data['coupon_code']);
             }
             // Extra discount updates.
             if ($data['discounts']) {
                 foreach ((array) $data['discounts'] as $did => $discount) {
                     // Unset some discount details.
                     unset($data['discounts'][$did]['codes']);
                     unset($data['discounts'][$did]['codes_used']);
                     unset($data['discounts'][$did]['code_history']);
                     unset($data['discounts'][$did]['conditions']);
                 }
             }
             // Update order data? Merge.
             if (isset($data['order']) && is_array($cart['order'])) {
                 if ($data['order']) {
                     if ($data['order']['shipping']) {
                         $data['order']['shipping'] = array_merge((array) $cart['order']['shipping'], (array) $data['order']['shipping']);
                     }
                     $data['order'] = $cart['order'] = array_merge($cart['order'], (array) $data['order']);
                 }
             }
             // Update shipping total?
             if ($data['order'] || $data['items']) {
                 // @TODO: Make sure we don't need this.
                 //$data['shipping_total'] = Carts::get_shipping_total($cart);
             }
             // Use credit?
             if ($data['credit_total']) {
                 // Validate.
                 $data['credit_total'] = Carts::get_credit_total(merge($cart, $data));
             }
         }
     }, 'validate:order' => function ($order, $field, $params, $model) {
         // Validate with orders collection.
         $order[':validate'] = true;
         $result = get("/orders", $order);
         // Apply errors to cart model?
         foreach ((array) $result['errors'] as $field => $error) {
             $model->error($error, 'order', $field);
         }
     });
 }
Пример #19
0
    unlink($outputFile);
    unlink($over);
}
if (isset($GLOBALS["HTTP_RAW_POST_DATA"])) {
    // Get the data
    $imageData = $GLOBALS['HTTP_RAW_POST_DATA'];
    $array_variable = get_variable($path_folder_save);
    // $over = 'imagesVillagesBattles/over.png';
    $over = $array_variable[1];
    // $n = $array_variable[5];
    // Remove the headers (data:,) part.
    // A real application should use them according to needs such as to check image type
    $filteredData = substr($imageData, strpos($imageData, ",") + 1);
    // Need to decode before saving since the data we received is already base64 encoded
    $unencodedData = base64_decode($filteredData);
    $f = fopen($over, 'wb');
    stream_filter_append($fh, 'convert.base64-decode');
    // Do a lot of writing here. It will be automatically decoded from base64.
    fclose($f);
    file_put_contents($over, $unencodedData);
    $size = getimagesize($over);
    $w = $size[0];
    $h = $size[1];
    merge($w, $h);
    write_comments();
}
?>



Пример #20
0
     require CLASS_DIR . 'options/split.php';
     rl_split();
     break;
 case 'split_go':
     if (!empty($options['disable_split'])) {
         break;
     }
     require CLASS_DIR . 'options/split.php';
     split_go();
     break;
 case 'merge':
     if (!empty($options['disable_merge'])) {
         break;
     }
     require CLASS_DIR . 'options/merge.php';
     merge();
     break;
 case 'merge_go':
     if (!empty($options['disable_merge'])) {
         break;
     }
     require CLASS_DIR . 'options/merge.php';
     merge_go();
     break;
 case 'rename':
     if (!empty($options['disable_rename'])) {
         break;
     }
     require CLASS_DIR . 'options/rename.php';
     rl_rename();
     break;
Пример #21
0
<?php

include "globals.php";
if (!$_GET) {
    $smarty->display("index.html");
    die;
} else {
    $result = do_search($_GET['keywords'], $_GET['start'], "uludag.org.tr");
    $result2 = do_search($_GET['keywords'], $_GET['start'], "pardus.org.tr");
    //echo "<pre>";
    //print_r(merge($result, $result2));
    //echo "</pre>";
    $smarty->assign("results", merge($result, $result2));
    $smarty->display("search.html");
    die;
}
function do_search($kw, $start, $domain)
{
    global $config;
    $searchString = $kw . ' site:liste.' . $domain;
    $google = new googleClient($config['core']['licensekey']);
    if ($start) {
        $st = $start;
    } else {
        $st = 0;
    }
    if ($google->search($searchString, $st)) {
        $result = $google->results;
    }
    $result->searchTime = round($result->searchTime, 2);
    for ($i = 0; $i < count($result->resultElements); $i++) {
Пример #22
0
$main4dir = array($textdir['Readme'], $textdir['Administrator Documentation']);
$main4tooltip = array($langu, $langu);
$getsmain4 = array(array('langu', urlencode($langu)), array('langu', urlencode($langu)));
$gets2main4 = array(array('', ''), array('', ''));
// Fixes "Lang" and "Download" as preceding all Download subfiles (Readme and Admin. Documentation)
$fixed4 = array($browserpgs[0] . "?" . $gets[0][0] . "=" . $gets[0][1], $mainpgs[1] . "?" . $getsmain[1][0] . "=" . $getsmain[1][1]);
$fixed4name = array($browsernames[0], $mainpgnames[1]);
$fixed4tooltip = array($tooltips[0], $langu);
$fixed4dir = array($browserdirs[0], $mainpgdirs[1]);
// Joined (alphabetical) items
$pgnames = merge($browsernames, $mainpgnames, $main3name, $main4name);
$pgdirs = merge($browserdirs, $mainpgdirs, $main3dir, $main4dir);
$pgpgs = merge($browserpgs, $mainpgs, $main3, $main4);
$pggets = merge($gets, $getsmain, $getsmain3, $getsmain4);
$pggets2 = merge($gets2, $gets2main, $gets2main3, $gets2main4);
$pgtooltips = merge($tooltips, $mainpgtooltips, $main3tooltip, $main4tooltip);
$pgdata = array($pgnames, $pgdirs, $pgpgs, $pggets, $pggets2, $pgtooltips);
$pgdata = remove_dups($pgdata, 0);
array_multisort($pgdata[0], $pgdata[1], $pgdata[2], $pgdata[3], $pgdata[4], $pgdata[5]);
$merged = $pgdata;
//////////// The following creates the navigation bar ////////////
if ($navigatoryes) {
    $navprint .= "\n<div class='navigatorhead'>\n\t";
    $v = 0;
    $totalcells = count($mainpgnames);
    for ($i = 0; $i < $totalcells; $i++) {
        $r = 0;
        if ($getsmain[$v][0] != "") {
            $getdatamain = "?" . $getsmain[$v][0] . "=" . $getsmain[$v][1];
            $r++;
        } else {
Пример #23
0
function MAX_arrayMergeRecursive(&$a, &$b)
{
    $keys = array_keys($a);
    foreach ($keys as $key) {
        if (isset($b[$key])) {
            if (is_array($a[$key]) && is_array($b[$key])) {
                //????????? the 'merge' fn not only is not a PHP fn, it's not defined anywhere, go figure ...
                merge($a[$key], $b[$key]);
            } else {
                $a[$key] = $b[$key];
            }
        }
    }
    $keys = array_keys($b);
    foreach ($keys as $key) {
        if (!isset($a[$key])) {
            $a[$key] = $b[$key];
        }
    }
}
Пример #24
0
function evolve(&$population)
{
	$indexA = rand(0, count($population) - 1);
	do {
		$indexB = rand(0, count($population) - 1);
	} while($indexB == $indexA);
	
		

	$a = $population[$indexA];
	$b = $population[$indexB];

	printf("%d : %d\n", $indexA, $indexB);
	
	$choose = chooseGenome($a, $b);

	switch ($choose) {
		case 1:
			array_splice($population, $indexB, 1);
			break;

		case 2:
			array_splice($population, $indexA, 1);
			break;
	}

	if(count($population) == 2) {
		printf("Merging.\n");
		$cd = merge($population[0], $population[1]);
		$population = array_merge($population, $cd);
	}

	if(rand(1,5) == 1) {
		$index = rand(0, count($population) - 1);
		printf("\t\t\tMutating %d\n", $index);
		mutate($population[$index]);
	}

}
Пример #25
0
/**
 * The famous merge sort algorithm implementation
 * 
 * $data is an array formatted as follow (with $i as an index):
 * list($song_id, $usr_id, $country_code) = $data[$i];
 * 
 * @param $data, a multidimensional array containing the log data
 * @param $comparator1, the first comparator index (0: song_id, 1: usr_id, 2: country_code)
 * @param $comparator2, the second comparator index (0: song_id, 1: usr_id, 2: country_code)
 */
function mergeSort($data, $comparator1, $comparator2)
{
    if (count($data) <= 1) {
        return $data;
    }
    $mid = count($data) / 2;
    $left = array_slice($data, 0, $mid);
    $right = array_slice($data, $mid);
    $left = mergeSort($left, $comparator1, $comparator2);
    $right = mergeSort($right, $comparator1, $comparator2);
    return merge($left, $right, $comparator1, $comparator2);
}
Пример #26
0
         }
         if ($projects_changed) {
             finish($projects, 'projects', null);
         }
     }
 } else {
     if ($_POST['method'] == 5) {
         $categories[$_POST['category']] = $_POST['newname'];
         finish($categories, 'categories', PP_MESSAGE_CATEGORYRENAMED);
     } else {
         if ($_POST['method'] == 6) {
             if (get_project($_POST['category'], $_POST['name']) != null) {
                 echo message(PP_MESSAGE_SAMENAMEEXISTS, 'alert-danger');
             } else {
                 $_POST['link'] = correct_link($_POST['link']);
                 $projects = merge($projects, 'projects', array(array('name' => htmlspecialchars($_POST['name']), 'description' => htmlspecialchars($_POST['description']), 'link' => htmlspecialchars($_POST['link']), 'category' => htmlspecialchars($_POST['category']))), PP_MESSAGE_PROJECTADDED, true, true);
             }
         } else {
             if ($_POST['method'] == 7) {
                 $projects = remove($projects, 'projects', $_POST['project'], PP_MESSAGE_PROJECTREMOVED);
             } else {
                 if ($_POST['method'] == 8) {
                     if ($_POST['old-category'] != $_POST['category']) {
                         foreach ($projects as $project) {
                             if ($project['name'] != $_POST['name']) {
                                 continue;
                             }
                             echo message(PP_MESSAGE_SAMENAMEEXISTS, 'alert-danger');
                         }
                     } else {
                         if ($_POST['old-name'] != $_POST['name']) {
Пример #27
0
<?php

namespace x7;

$user = $ses->current_user();
$req->require_permission('access_admin_panel');
$ses->check_bans();
$admin = $x7->admin();
$room = array();
$room_id = isset($_GET['room_id']) ? $_GET['room_id'] : 0;
if ($room_id) {
    $sql = "\n\t\t\tSELECT\n\t\t\t\t*\n\t\t\tFROM {$x7->dbprefix}rooms\n\t\t\tWHERE\n\t\t\t\tid = :room_id\n\t\t";
    $st = $db->prepare($sql);
    $st->execute(array(':room_id' => $room_id));
    $room = $st->fetch();
    $st->closeCursor();
}
if (!$room && $room_id) {
    $ses->set_message($x7->lang('room_not_found'));
    $req->go('admin_rooms');
}
$post = $ses->get_flash('forward');
$room = merge($room, $post);
$x7->display('pages/admin/edit_room', array('room' => $room, 'menu' => $admin->generate_admin_menu($room_id ? 'edit_room' : 'create_room')));
Пример #28
0
    $j = 0;
    $k = 0;
    $f = sizeof($first);
    $s = sizeof($second);
    while ($i < $f && $j < $s) {
        if ($first[$i] <= $second[$j]) {
            $result[$k] = $first[$i];
            $i++;
        } else {
            $result[$k] = $second[$j];
            $j++;
        }
        $k++;
    }
    if ($i < $f) {
        for ($p = $i; $p < $f; $p++) {
            $result[$k] = $first[$p];
            $k++;
        }
    }
    if ($j < $s) {
        for ($p = $j; $p < $s; $p++) {
            $result[$k] = $second[$p];
            $k++;
        }
    }
    return $result;
    // END
}
print_r(merge([1, 2, 3], [7, 8, 9, 10]));
Пример #29
0
}
// END FOREACH
$eval_passes = array();
$eval_passes[] = "plural_of";
$eval_passes[] = "selected_from";
$eval_passes[] = "is_a_kind_of";
foreach ($eval_passes as $to_eval) {
    foreach ($q as $aq) {
        $obj1 = str_replace(" ", "_", $aq['obj1']);
        $obj2 = str_replace(" ", "_", $aq['obj2']);
        $obj3 = str_replace(" ", "_", $aq['obj3']);
        $obj1 = fix_reserved($obj1);
        $obj3 = fix_reserved($obj3);
        if ($obj2 == $to_eval) {
            foreach ($dict as $dk => $dv) {
                $af = merge($obj2, $obj1, $obj3, $dk, $dv);
            }
        }
    }
}
// END FOREADCH
function idfordersort($a, $b)
{
    if ($a == $b) {
        return 0;
    }
    $has_id_check = strpos($a, "id") !== false && strpos($b, "id") === false;
    $both_are_id = strpos($a, "id") !== false && strpos($b, "id") !== false;
    if ($both_are_id) {
        $has_id_check = $a == "id" && $b != "id";
    }
Пример #30
0
<?php

namespace x7;

$user = $ses->current_user();
$req->require_permission('access_admin_panel');
$ses->check_bans();
$admin = $x7->admin();
$group = array();
$id = isset($_GET['id']) ? $_GET['id'] : 0;
if ($id) {
    $sql = "\n\t\t\tSELECT\n\t\t\t\t*\n\t\t\tFROM {$x7->dbprefix}groups\n\t\t\tWHERE\n\t\t\t\tid = :id\n\t\t";
    $st = $db->prepare($sql);
    $st->execute(array(':id' => $id));
    $group = $st->fetch();
    $st->closeCursor();
}
if (!$group && $id) {
    $ses->set_message($x7->lang('group_not_found'));
    $req->go('admin_list_groups');
}
$post = $ses->get_flash('forward');
$group = merge($group, $post);
$x7->display('pages/admin/edit_group', array('group' => $group, 'allow_avatar' => $x7->supports_image_uploads(), 'avatar_max_size' => $x7->upload_max_size_mb(), 'menu' => $admin->generate_admin_menu($id ? 'edit_group' : 'create_group')));