<?php
require ('authentication_member.php');
?>
<?php

/* 信誉提交 */  
/* 162100源码 - 162100.com */


if (POWER == 0) {
  err('请<a href="./login.php">登陆</a>。');
}

  
if (empty($_POST['act']) || !preg_match('/^([^\x00-\x7f]|\w){3,45}$/', $_POST['act'])) {
  err('提交被拒绝！图片名称不能空！且限用汉字、数字、英文及下划线组成！长度范围为3-45字符。注：中文占3个字符，其它等占1个。即：纯中文可输入15字，英文或数字或英语符号可输入45字。');
}


$inis = ini_get_all();
$uploadmax = $inis['upload_max_filesize'];
/*
[global_value] => 2M
[local_value] => 2M
[access] => 6
*/

if (!is_array($_FILES['uploadfile']) || !$_FILES['uploadfile']['size']) {
  err('提示：上传logo出现空值！原因分析：1、上传图片为空 2、图片超过系统最大上传限量'.$uploadmax['global_value'].'（'.$uploadmax['local_value'].'）。');
}
$max_size = 100 * 10000;
if ($_FILES['uploadfile']['size'] > $max_size) {
  err('提示：上传logo的文件请小于'.($max_size/1000).'KB。');
}
if (!preg_match('/\.(gif|jpg|png)$/i', $_FILES['uploadfile']['name'], $im)) {
  err('提示：上传logo请选择一个有效的文件：允许的格式有（gif|jpg|png）。');
}
unset($inis, $uploadmax, $max_size);

if ($fp = @fopen($_FILES['uploadfile']['tmp_name'], 'rb')) {
  $img_contents = @fread($fp, $_FILES['uploadfile']['size']);
  @fclose($fp);
} else {
  $img_contents = @file_get_contents($_FILES['uploadfile']['tmp_name']);
}
if (preg_match('/<\?php|eval|POST|base64_decode|base64_encode/i', $img_contents, $m_err)) {
  err('提示！禁止提交。该文件含有禁止的代码'.str_replace('?', '\?', $m_err[0]).'。');
  unset($m_err);
}

if (!isset($sql['db_err'])) {
  db_conn();
}
if ($sql['db_err'] != '') {
  err($sql['db_err']);
}
$upload_filename = 'credit-'.$_POST['act'].'.'.strtolower($im[1]);

if ($web['uploadto'] == 1) {
  @mysql_query('DELETE FROM `'.$sql['pref'].''.$sql['data']['承载上传数据的表名'].'` WHERE title LIKE "credit-'.$_POST['act'].'.%" AND username="'.$session[0].'"', $db);
  @mysql_query('REPLACE INTO `'.$sql['pref'].''.$sql['data']['承载上传数据的表名'].'` (`title`,`text`,`type`,`username`,`date`) VALUES ("'.$upload_filename.'","'.addslashes($img_contents).'","'.addslashes($_FILES['uploadfile']['type']).'","'.$session[0].'",DATE_ADD(UTC_TIMESTAMP(), INTERVAL '.floatval($web['time_pos']).' HOUR))', $db);
  unset($img_contents);
  if (!abs(@mysql_affected_rows()) > 0) {
    err('提示：上传出现错误！存入数据失败。请暂时停止上传。');
  }
  @unlink('__temp__/temp/'.urlencode($upload_filename));
} else {

  if (@move_uploaded_file($_FILES['uploadfile']['tmp_name'], '__temp__/temp/'.urlencode($upload_filename))) {
    $arr = array('jpg' => true, 'gif' => true, 'png' => true);
    unset($arr[strtolower($im[1])]);
    foreach ($arr as $key => $v) {
      $old_p = '__temp__/temp/credit-'.urlencode($_POST['act']).'.'.$key;
      if (file_exists($old_p)) @unlink($old_p);
    }
    unset($arr, $old_p, $key, $v);
  } else {
    err('提示：上传出现错误！请暂时停止上传。');
  }
}




if (POWER >= 4) {
  $chk = '0';
  $out = '您是管理员，没有给您加信誉值';
} else {
  $chk = '1';
  $out = '请等待审核';
}

$open = $_POST['open'] != 1 ? '0' : '1'; //1公开，0不公开

@mysql_query('UPDATE `'.$sql['pref'].''.$sql['data']['承载财务数据的表名'].'` SET `date`=DATE_ADD(UTC_TIMESTAMP(), INTERVAL '.floatval($web['time_pos']).' HOUR),`check_credit`="'.$chk.'",`other`="'.$open.'credit-'.urlencode($_POST['act']).'.'.strtolower($im[1]).'" WHERE (username="'.$session[0].'" AND type="1") AND description="'.$_POST['act'].'"', $db);
if (!@mysql_affected_rows() > 0) {
  @mysql_query('INSERT INTO `'.$sql['pref'].''.$sql['data']['承载财务数据的表名'].'` (`username`,`type`,`description`,`date`,`check_credit`,`other`) VALUES ("'.$session[0].'","1","'.$_POST['act'].'",DATE_ADD(UTC_TIMESTAMP(), INTERVAL '.floatval($web['time_pos']).' HOUR),"'.$chk.'","'.$open.'credit-'.urlencode($_POST['act']).'.'.strtolower($im[1]).'")', $db);
}

@mysql_close();

alert('图片上传成功！'.$out, 'member.php?get=mycredit');



?>