RPT011.php 15.2 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474
<?php 
//*****************************************************************************
//* 
//* プログラム名:営業日報
//* プログラムID:RPT011.php
//* 機能        :営業日報一覧画面 一覧部分
//* 作成者      :
//* 
//*****************************************************************************
header("Content-type: text/html; charset=EUC-JP");

//***************************
//* インクルードファイル
//***************************
include("include/session_start.inc");
include("include/SessionChk.inc");
include("include/STRING.inc");
include("inc/subRepURI.inc");

include('./include/smarty.conf');
include("./include/dbcon.inc");				//DB接続

$strTempPath="./temp/".$PHP_FOLDER_NAME."/RPT/";

//URL関数
function link_url($str){
	$regex = "((https?://|ftp://)([0-9A-Za-z:_?./~%;()=+#-]|&amp;)+)";
	$str = eregi_replace($regex, "<a href=\"\\1\" target=\"_blank\">\\1</a>", $str);
	$regex_mail = "((mailto:)?([0-9A-Za-z._-]+@[0-9A-Za-z.-]+))";
	$str = eregi_replace($regex_mail, "<a href=\"mailto:\\3\">\\1</a>", $str);
	return $str;
}

$strSQL="";
$objRec="null";
$strSyain="";
$objRecSyain="null";
$strChek="";
$objRecChek="null";

if (empty($intPage)){
	$intPage=0;
}

//自分の所属を取得
$strSQL_s = "SELECT syozoku_cd FROM syozoku_tbl WHERE syain_cd ='$PHP_SYAIN_CD' ";
$objRec_s = pg_exec($strSQL_s);
if($objRec_s==false){
	echo("SQL実行に失敗しました(SELECT)");
	exit;
}

$Customer_group = mb_convert_encoding(subRepURI($Customer_group), "EUC-JP", "auto");
$Customer       = mb_convert_encoding(subRepURI($Customer), "EUC-JP", "auto");
$Visit_input    = mb_convert_encoding(subRepURI($Visit_input), "EUC-JP", "auto");

//一覧
if($disp_mode == 1){
	$intBR = 104;
	$strTpl = "RPT011.tpl";
	for ($intSyozoku=0; $intSyozoku < pg_numrows($objRec_s); $intSyozoku++){
		$objSyozoku = pg_fetch_object($objRec_s, $intSyozoku);
		if ($intSyozoku==0){
			$strJoken= " Where (bumon_cd =0 or bumon_cd = " .$objSyozoku->syozoku_cd ;
		}else{
			$strJoken=$strJoken. " or bumon_cd=".$objSyozoku->syozoku_cd ;
		}
	}
	if (pg_numrows($objRec_s) > 0){
		$strJoken=$strJoken. ") ";
	}else{
		$strJoken= " Where (bumon_cd =0)";
	}
	//営業日報情報取得
	//$strSQL="SELECT * FROM eigyo_memo_tbl,peigyou_tbl ".$strJoken.
	$strSQL="SELECT read_flg,eigyo_memo_tbl.seq,date,time,time_e,tori_name,charge,eigyo_memo_tbl.syain_cd,syain_list,visit_purpose,memo,subject,bikou,update FROM eigyo_memo_tbl,peigyou_tbl ".$strJoken.
				" and ( eigyo_memo_tbl.seq = peigyou_tbl.seq and peigyou_tbl.syain_cd ='$PHP_SYAIN_CD' ) ".
//				" Order by read_flg,date DESC,time DESC,eigyo_memo_tbl.seq DESC ";
			" Order by read_flg,eigyo_memo_tbl.update DESC NULLS LAST ,date DESC,time DESC,eigyo_memo_tbl.seq DESC ";

//作成一覧
}else if($disp_mode == 2){
	$intBR = 68;
	$strTpl = "RPT012.tpl";
	//管理者権限がある場合は全て表示
	if($admin_session=="administrator" || $PHP_BIT[6] == 1){
		$strSQL="SELECT * FROM eigyo_memo_tbl ".
					" Order by date DESC,time DESC,eigyo_memo_tbl.seq DESC ";
	}else{
		//作成済みの営業日報情報取得
		$strSQL="SELECT * FROM eigyo_memo_tbl Where syain_cd='$PHP_SYAIN_CD'" .
					" Order by date DESC,time DESC,seq DESC ";
	}
//検索一覧
}else if($disp_mode == 3){
	$intBR = 104;
	$strTpl = "RPT011.tpl";
	//日付検索
	if ($start_y !="00" && $start_m != "00" && $start_d !="00" && $end_y != "00" && $end_m != "00" && $end_d != "00" ){
		$strDateJoken=" and (date between '" . $start_y ."/" . $start_m ."/". $start_d ."' and '" . $end_y ."/" . $end_m ."/". $end_d . "')";
	}
	//グループ
	if($chk_tori==0 && $Customer_group !=""){
		//取引先情報取得
		$strSQLtori="SELECT tori_name,tori_group FROM torihiki_tbl Where tori_group=".$Customer_group;
		$objRectori = pg_exec($strSQLtori);
		if($objRectori==false){
			echo("SQL実行に失敗しました(SELECT)");
			exit;
		}
		if (0 < pg_numrows($objRectori)){
			for ($inttori=0; $inttori < pg_numrows($objRectori); $inttori++){
				$objtori = pg_fetch_object($objRectori, $inttori);
				if($inttori==0){
					$strGroupJoken=" and (tori_name='".$objtori->tori_name."'";
				}else{
					$strGroupJoken=$strGroupJoken." or tori_name='".$objtori->tori_name."'";
				}
			}
			$strGroupJoken=$strGroupJoken.")";
		}else{
			$strGroupJoken=" and (tori_name='".$objtori->tori_name."')";
		}
	}
	//取引先
	if($chk_tori==1 && $Customer !=""){
		$strtoriJoken=" and (tori_name like '%".addslashes($Customer)."%')";
	
	}
	//取引入力
	if($chk_tori==2 && $Visit_input !=""){
		$strInputJoken=" and (tori_name like '%".addslashes($Visit_input)."%')";
	}
	//訪問者選択
	if($Caller != ""){
		$strCallerJoken=" and (syain_list like '%/".$Caller."/%')";
	}
	//日付条件
	if($strDateJoken !=""){
		$strJoken=$strDateJoken;
	}
	//取引先選択条件
	if($strJoken != "" && $strtoriJoken != ""){
		$strJoken= $strJoken." ".$strtoriJoken;
	}elseif($strJoken=="" && $strtoriJoken != ""){
		$strJoken=$strtoriJoken;
	}
	//取引先入力
	if($strJoken != "" && $strInputJoken != ""){
		$strJoken= $strJoken." ".$strInputJoken;
	}elseif($strJoken=="" && $strInputJoken != ""){
		$strJoken=$strInputJoken;
	}
	//取引先グループ条件
	if($strJoken != "" && $strGroupJoken != ""){
		$strJoken= $strJoken."  ".$strGroupJoken;
	}elseif($strJoken=="" && $strGroupJoken != ""){
		$strJoken=$strGroupJoken;
	}
	//訪問者条件
	if($strJoken != "" && $strCallerJoken != ""){
		$strJoken= $strJoken." ".$strCallerJoken;
	}elseif($strJoken=="" && $strCallerJoken != ""){
		$strJoken=$strCallerJoken;
	}

	//営業日報情報取得
	//	$strSQL="SELECT * FROM eigyo_memo_tbl,peigyou_tbl Where (peigyou_tbl.syain_cd='$PHP_SYAIN_CD' and eigyo_memo_tbl.seq = peigyou_tbl.seq ) ".$strJoken.
		$strSQL="SELECT read_flg,eigyo_memo_tbl.seq,date,time,time_e,tori_code,tori_name,charge,eigyo_memo_tbl.syain_cd,syain_list,visit_purpose,memo,subject,bikou ".
				" FROM eigyo_memo_tbl,peigyou_tbl Where (peigyou_tbl.syain_cd='$PHP_SYAIN_CD' and eigyo_memo_tbl.seq = peigyou_tbl.seq ) ".$strJoken.
//				" Order by read_flg,date DESC,time DESC,eigyo_memo_tbl.seq DESC ";
			" Order by read_flg,eigyo_memo_tbl.update DESC NULLS LAST,date DESC,time DESC,eigyo_memo_tbl.seq DESC ";

}

$objRec = pg_exec($strSQL);
if($objRec==false){
	echo("SQL実行に失敗しました(SELECT)");
	exit;
}
if (pg_numrows($objRec)==0){
	$strDisp = " disabled";
}

//<!--営業日報-->
if (($intPage > 0) && (pg_numrows($objRec) > (10 * ($intPage+1)))){
	$PageBackPrm = $intPage-1;
	$PageNextPrm = $intPage+1;
}elseif(($intPage > 0) && (pg_numrows($objRec) <= (10 * ($intPage+1)))){
	$PageBackPrm = $intPage-1;
	$PageNextPrm = "";
}elseif(($intPage == 0) && (pg_numrows($objRec) > (10 * ($intPage+1)))){
	$PageBackPrm = "";
	$PageNextPrm = $intPage+1;
}else{
	$PageBackPrm = "";
	$PageNextPrm = "";
}

//チェックボックス表示確認
$intEndCnt=10 * ($intPage+1);
if ($intEndCnt>pg_numrows($objRec)){
	$intEndCnt=pg_numrows($objRec);
}
$intDispFlg=0;
for ($intCnt = 10 * $intPage; $intCnt < $intEndCnt; $intCnt++) {
	$objData = pg_fetch_object($objRec, $intCnt);
	if ($objData->read_flg==0){
		$intDispFlg=1;
		break;
	}
}

if ($intDispFlg!=1){ $PageCheak = " disabled=true";}
$o_smarty->assign('PageCheak',$PageCheak);
$o_smarty->assign('intPage',$intPage);
if ($intDispFlg!=1){ $PageDel = " disabled=true";  }
$o_smarty->assign('PageDel',$PageDel);

//終了ページの取得
$intEndCnt=10 * ($intPage+1);
if ($intEndCnt>pg_numrows($objRec)){
	$intEndCnt=pg_numrows($objRec);
}

$intCnt2=0;
for ($intCnt = 10 * $intPage; $intCnt < $intEndCnt; $intCnt++) {
	$objData = pg_fetch_object($objRec, $intCnt);

	//社員名取得
	$strJyoken=str_replace("/","' or syain_cd='",$objData->syain_list);
	$strSyain="SELECT name_kj_sei,name_kj_mei FROM syain_tbl Where syain_cd=" . "'" .$strJyoken ."' Order by disp_rank";
	$objRecSyain = pg_exec($strSyain);
	if($objRecSyain==false){
		echo("SQL実行に失敗しました(SELECT)");
		exit;
	}
			
	if (($objData->time =="") && ($objData->time_e =="")){
		$strTime[$intCnt2]="";
	}elseif (($objData->time !="") && ($objData->time_e !="")){
		$strTime[$intCnt2]=$objData->time ."〜" .$objData->time_e;
	}elseif (($objData->time !="") && ($objData->time_e =="")){
		$strTime[$intCnt2]=$objData->time ."〜";
	}

	$PhpDate[$intCnt2] = $objData->date;
	$PhpTime[$intCnt2] = $objData->time;
	$PhpTori_name[$intCnt2] = $objData->tori_name;
	$PhpCharge[$intCnt2] = $objData->charge;
	$PhpSeq[$intCnt2] = $objData->seq;
	//最終更新日
	if (is_null($objData->update)==false){
		$PhpUpDate[$intCnt2] = substr($objData->update, 0, 4)."/".substr($objData->update, 4, 2)."/".substr($objData->update, 6, 2)." ".substr($objData->update, 8, 2).":".substr($objData->update, 10, 2);
	}else{
		$PhpUpDate[$intCnt2]="";
	}

	for ($intSyainCnt = 0; $intSyainCnt < pg_numrows($objRecSyain); $intSyainCnt++) {
		$objSyain = pg_fetch_object($objRecSyain, $intSyainCnt);
		$PhpHoumon[$intCnt2] .= $objSyain->name_kj_sei.$objSyain->name_kj_mei."<BR>";
	}

	//訪問目的
	$visit_purpose[$intCnt2] = link_url(str_replace ("\n","<br>",htmlspecialchars($objData->visit_purpose)));

	//メモ
	//20091014
	//$memo[$intCnt2] = link_url(str_replace ("\r\n","<br>",htmlspecialchars($objData->memo)));
	$memo[$intCnt2] = link_url(str_replace ("\n","<br>",htmlspecialchars($objData->memo)));

	//課題
	//20091014
	//$Subject[$intCnt2] = link_url(str_replace ("\r\n","<br>",htmlspecialchars($objData->subject)));
	$Subject[$intCnt2] = link_url(str_replace ("\n","<br>",htmlspecialchars($objData->subject)));

	//備考
	//20091014
	//$Note[$intCnt2] = link_url(str_replace ("\r\n","<br>",htmlspecialchars($objData->bikou)));
	$Note[$intCnt2] = link_url(str_replace ("\n","<br>",htmlspecialchars($objData->bikou)));

	$read_flg[$intCnt2] = (int) $objData->read_flg;
	if ($objData->read_flg==0){
		//$read_flg[$intCnt2] = '<INPUT type="checkbox" name="check_seq" value="'.$objData->seq.'">';
		$read_str[$intCnt2] = "<font color='#FF0000'>未読</font>";
		$BgColor[$intCnt2]  = "tblUn";
	}else{
		$read_str[$intCnt2] = "既読";
		$BgColor[$intCnt2]  = "tblAl";
	}
	$NoCnt[$intCnt2]=$intCnt2;

	//本人??
	if($objData->syain_cd == $PHP_SYAIN_CD){
		$modi_flg[$intCnt2] = 1;
	}

	//報告者名取得
	$strSyain="SELECT name_kj_sei,name_kj_mei FROM syain_tbl Where syain_cd=" . "'" .$objData->syain_cd ."'";
	$objRecSyain = pg_exec($strSyain);
	if($objRecSyain==false){
		echo("SQL実行に失敗しました(SELECT)");
		exit;
	}
	$objData = pg_fetch_object($objRecSyain, 0);
	$maker[$intCnt2] = $objData->name_kj_sei.$objData->name_kj_mei;
			
	//コメント
	$strSQL = "select seq, comm_seq, eigyo_comm_tbl.syain_cd,comment,comm_date,syain_tbl.name_kj_sei,syain_tbl.name_kj_mei from eigyo_comm_tbl ";
	$strSQL .= "join syain_tbl on syain_tbl.syain_cd = eigyo_comm_tbl.syain_cd  ";
	$strSQL .= "where seq = ".$PhpSeq[$intCnt2]." order by comm_date desc";
	$objComm = pg_exec($strSQL);
	if($objComm==false){
		echo("SQL実行に失敗しました(SELECT)");
		exit;
	}
	if(pg_numrows($objComm) > 0){
		for($i=0;$i<pg_numrows($objComm);$i++){
			$commData = pg_fetch_object($objComm, $i);
			//20091014
			//$tempComm = link_url(str_replace ("\r\n","<br>",htmlspecialchars($commData->comment)));
			$tempComm = link_url(str_replace ("\n","<br>",htmlspecialchars($commData->comment)));

			$strDate = (int) substr(($commData->comm_date),0,4);
			$strDate .= "年";
			$strDate .= (int) substr(($commData->comm_date),4,2);
			$strDate .= "月";
			$strDate .= (int) substr(($commData->comm_date),6,2);
			$strDate .= "日";
			$strDate .= (int) substr(($commData->comm_date),8,2);
			$strDate .= "時";
			$strDate .= (int) substr(($commData->comm_date),10,2);
			$strDate .= "分";
			$strComm[$intCnt2] .= $tempComm;

			//添付ファイル
			//echo $strSQL;
			$strSQL = "SELECT";
			$strSQL .= " * ";
			$strSQL .= "FROM";
			$strSQL .= " common_file_tbl ";
			$strSQL .= "WHERE ";
			$strSQL .= " type = 'RPT' AND ";
			$strSQL .= " seq1 = ".$PhpSeq[$intCnt2]." AND ";
			$strSQL .= " seq2 = ".$commData->comm_seq." ";
			$strSQL .= "ORDER BY ";
			$strSQL .= " file_seq ASC ";
			$objCmFileRec = pg_exec($strSQL);
			if($objCmFileRec==false){
				echo("SQL実行に失敗しました(SELECT)");
				exit;
			}
			if(pg_numrows($objCmFileRec) > 0){
				$objCmFileData = pg_fetch_object($objCmFileRec, 0);
				$strComm[$intCnt2] .= "<br>";
				$strComm[$intCnt2] .= '<a href="javascript:DownFile(';
				$strComm[$intCnt2] .= "'".$strTempPath.$objCmFileData->file_name."','".$objCmFileData->file_name_org."');";
				$strComm[$intCnt2] .= '">'.$objCmFileData->file_name_org;
				$strComm[$intCnt2] .= "</a>";
			}

			$strComm[$intCnt2] .= "<BR>(".($commData->name_kj_sei).($commData->name_kj_mei)." ";
			$strComm[$intCnt2] .= $strDate.")";
			if(trim($commData->syain_cd) == $PHP_SYAIN_CD || $PHP_BIT[6] == 1){
				$strComm[$intCnt2] .="<input type='button' value='削除' onClick='comm_del(".$commData->seq.",".$commData->comm_seq.");'>";
			}
			$strComm[$intCnt2] .= "<br>";
			if ($i!=pg_numrows($objComm)-1){
				$strComm[$intCnt2] .= "<hr width=95%>";
			}
		}
	}else{
		$strComm[$intCnt2] = " ";
	}

	//添付ファイル
	$strSQL = "SELECT";
	$strSQL .= " * ";
	$strSQL .= "FROM";
	$strSQL .= " common_file_tbl ";
	$strSQL .= "WHERE ";
	$strSQL .= " type = 'RPT' AND ";
	$strSQL .= " seq1 = ".$PhpSeq[$intCnt2]." AND ";
	$strSQL .= " seq2 = 0 ";
	$strSQL .= "ORDER BY ";
	$strSQL .= " file_seq ASC ";
	$objFileRec = pg_exec($strSQL);
	if($objFileRec==false){
		echo("SQL実行に失敗しました(SELECT)");
		exit;
	}
	if(pg_numrows($objFileRec) > 0){
		for($intI=0;$intI<pg_numrows($objFileRec);$intI++){
			$objFileData = pg_fetch_object($objFileRec, $intI);
			$File_Name[$intCnt2][$intI] = $strTempPath.$objFileData->file_name;
			$File_Org[$intCnt2][$intI]  = $objFileData->file_name_org;
		}
	}

	//閲覧数
	$strSQL = "SELECT count(*) as Dt_cnt FROM peigyou_tbl WHERE seq=".$PhpSeq[$intCnt2];
	$objDtCnt = pg_exec($strSQL);
	if($objDtCnt==false){
		echo("SQL実行に失敗しました(SELECT)");
		exit;
	}
	if(pg_numrows($objDtCnt) > 0){
		$objDtRec = pg_fetch_object($objDtCnt, 0);
		$Send_Cnt[$intCnt2]=$objDtRec->dt_cnt;
	}else{
		$Send_Cnt[$intCnt2]="0";
	}

	//既読数
	$strSQL = "SELECT count(*) as Dt_cnt FROM peigyou_tbl WHERE read_flg=1 AND seq=".$PhpSeq[$intCnt2];
	$objDtCnt = pg_exec($strSQL);
	if($objDtCnt==false){
		echo("SQL実行に失敗しました(SELECT)");
		exit;
	}
	if(pg_numrows($objDtCnt) > 0){
		$objDtRec = pg_fetch_object($objDtCnt, 0);
		$Read_Cnt[$intCnt2]=$objDtRec->dt_cnt;
	}else{
		$Read_Cnt[$intCnt2]=0;
	}
	$intCnt2++;
}
	
if(empty($PhpSeq) === false){
	$divList = join("/",$PhpSeq);
}

$o_smarty->assign('PageBackPrm',$PageBackPrm);
$o_smarty->assign('PageNextPrm',$PageNextPrm);
$o_smarty->assign('divList',$divList);
$o_smarty->assign('strComm',$strComm);

$o_smarty->assign('maker',$maker);
$o_smarty->assign('modi_flg',$modi_flg);

$o_smarty->assign('strTime',$strTime);
$o_smarty->assign('PhpDate',$PhpDate);
$o_smarty->assign('PhpTime',$PhpTime);
$o_smarty->assign('PhpSeq',$PhpSeq);
$o_smarty->assign('PhpHoumon',$PhpHoumon);
$o_smarty->assign('PhpTori_name',$PhpTori_name);
$o_smarty->assign('PhpCharge',$PhpCharge);

$o_smarty->assign('visit_purpose',$visit_purpose);
$o_smarty->assign('memo',$memo);
$o_smarty->assign('Subject',$Subject);
$o_smarty->assign('Note',$Note);

$o_smarty->assign('Send_Cnt',$Send_Cnt);
$o_smarty->assign('Read_Cnt',$Read_Cnt);

$o_smarty->assign('File_Name', $File_Name);
$o_smarty->assign('File_Org' , $File_Org);

$o_smarty->assign('pg_numrows',pg_numrows($objRec));
$o_smarty->assign('read_flg',$read_flg);
$o_smarty->assign('read_str',$read_str);
$o_smarty->assign('BgColor',$BgColor);
$o_smarty->assign('intPage',$intPage);
$o_smarty->assign('NoCnt',$NoCnt);

$o_smarty->assign('PhpUpDate',$PhpUpDate);

$o_smarty->assign('strDisp',$strDisp);

$o_smarty->display($strTpl);

?>