<?php include('../includes/header.php');
 include('../includes/checkSession.php');
 $order_type = "ASC";
$order_par = "brief_type";
if(isset($_REQUEST['otype']))
{
	$order_type = $_REQUEST['otype'];
}
if(isset($_REQUEST['opar']))
{
	$order_par = $_REQUEST['opar'];
}
 ?>
<?php if ($uacc == "Full Control") {?>
<?php if(!isset($_REQUEST['Edit'])){?>

<img src="../images/icon-heading.gif" width="12" height="13" border="0" /> <span class="lbrownlll7">Create a Brief</span>
<form id="form2" name="form2" method="post" action="BriefDB.php" onsubmit="return validatescopebrief()">
  <table width="100%" border="0">
    <tr class="ablks1">
      <th align="left" valign="top" scope="col">&nbsp;</th>
      <th align="left" valign="top"  scope="col">&nbsp;</th>
      <th align="left" valign="top"  scope="col">&nbsp;</th>
      <th align="left" valign="top"  scope="col">&nbsp;</th>
      <th align="left" valign="top"  scope="col">&nbsp;</th>
      <th align="left" valign="top"  scope="col">&nbsp;</th>
    </tr>
    <tr class="ablks1">
      <th width="9%" align="left" valign="middle" scope="col">Project Name*:</th>
      <th width="25%" align="left" valign="middle"  scope="col">
        <select name="projname" class="ablks1" id="projname">
          <option value="">Select ProjectCode - ProjectName</option>
          <?php
		 $result = mysql_query("SELECT * FROM projects where companySerial='$id' AND projStatus='1' order by projectName ASC");
   		while($row = mysql_fetch_array($result , MYSQL_ASSOC))
  		{
  		?>
        <option value="<?php echo $row['projectSerial']; ?>"><?php echo $row['projectCode']." - ".$row['projectName']; ?></option>
        <?php } ?>
      </select></th>
      <th align="left" valign="middle"  scope="col">Client*:</th>
      <th align="left" valign="middle"  scope="col"><label for="clientname"></label>
        <select name="clientname" class="ablks1" id="clientname">
          <option value="">Select ClientCode - ClientName</option>
          <?php

	  $result = mysql_query("SELECT clientCode, clientSerial, clientName, clientContactName FROM client where companySerial = '$id' AND clientStatus='1'");
		//echo $result."ll";
   		while($row = mysql_fetch_array($result , MYSQL_ASSOC))
  		{
			$clientSerial = $row["clientSerial"];
  		 echo "<option value='$clientSerial'>".$row["clientCode"]." - ".$row["clientName"]."</option>";
		}		

	  
	  ?>
      </select></th>
      <th width="8%" align="left" valign="middle"  scope="col">Name of Brief*:</th>
      <th width="27%" align="left" valign="middle"  scope="col"><label for="briefname"></label>
      <input name="briefname" type="text" class="ablks1" id="briefname" value="" size="30" /></th>
    </tr>
    <tr class="ablks1">
      <th align="left" valign="middle" scope="col">Type of Brief*: </th>
      <th align="left" valign="middle"  scope="col"><select name="brieftype" class="ablks1" id="brieftype">
        <option value="Client Brief">Client Brief</option>
        <option value="Design Brief">Design Brief</option>
        </select></th>
      <th align="left" valign="middle"  scope="col">Create*:</th>
      <th align="left" valign="middle"  scope="col"><label for="brieffrom">
        <select name="brieffrom" class="ablks1" id="brieffrom">
          <option value="From Scratch">From Scratch</option>
          <option value="From another Brief">From another Brief</option>
          </select>
      </label></th>
      <th align="left" valign="middle" scope="col">Copy from:</th>
      <th align="left" valign="middle"  scope="col"><select name="brieflist" class="ablks1" id="brieflist">
        <option value="Design Brief - xyz">Design Brief - xyz</option>
        <option value="Design Brief - abc">Design Brief - abc</option>
        <option value="Client Brief - 123">Client Brief - 123</option>
      </select> <input type="image" src="../images/icon-save.png"  width="15" height="15" border="0"  />&nbsp;<?php
  if (isset($_REQUEST["msg"])){  ?>
   <span class="fbrownl1">
     <?php echo $_REQUEST["msg"];?> </span>
  <?php }?></th>
    </tr>
    <tr class="ablks1">
      <th align="left" valign="top" scope="col">&nbsp;</th>
      <th colspan="5" align="left" valign="top" >&nbsp;</th>
    </tr>
    <tr class="ablks1">
      <th colspan="6" align="left" valign="top" scope="col"><hr /></th>
    </tr>
  </table>
</form><br>
<?php } else {
	
		$BID = $_REQUEST['Edit'];
   		$result = mysql_query("SELECT * FROM brief where brief_id='$BID'");		
   		$row = mysql_fetch_array($result , MYSQL_ASSOC);
		    $project_id = $row["project_id"];
            $client_id       = $row["client_id"];
	  		$brief_name  = $row["brief_name"];
			$brief_type   = $row["brief_type"];
			$brief_create    = $row["brief_create_from"];
            $brief_copy_from   = $row["brief_copy_from"];
            
	?>
<p><img src="../images/icon-heading.gif" width="12" height="13" border="0" /> <span class="lbrownlll7">Edit a Brief</span> </p>
<form id="form" name="form2" method="post" action="BriefDB.php?Edit=<?php echo $BID;?>" onsubmit="return validatescopebrief()">
  <table width="100%" border="0">
    <tr class="ablks1">
      <th align="left" valign="top" scope="col">&nbsp;</th>
      <th align="left" valign="top"  scope="col">&nbsp;</th>
      <th align="left" valign="top"  scope="col">&nbsp;</th>
      <th align="left" valign="top"  scope="col">&nbsp;</th>
      <th align="left" valign="top"  scope="col">&nbsp;</th>
      <th align="left" valign="top"  scope="col">&nbsp;</th>
    </tr>
    <tr class="ablks1">
      <th width="9%" align="left" valign="middle" scope="col">Project Name*:</th>
      <th width="25%" align="left" valign="middle"  scope="col">
        <select name="projname" class="ablks1" id="projname">
          <option value="">Select ProjectCode - ProjectName</option>
          <?php
		 $result = mysql_query("SELECT * FROM projects where companySerial='$id' AND projStatus='1'");
   		while($row = mysql_fetch_array($result , MYSQL_ASSOC))
  		{
  		?>
        <option value="<?php echo $row['projectSerial']; ?>" <?php if($row['projectSerial']==$project_id){?> selected="selected" <?php }?>><?php echo $row['projectCode']." - ".$row['projectName']; ?></option>
        <?php } ?>
      </select></th>
      <th align="left" valign="middle"  scope="col">Client*:</th>
      <th align="left" valign="middle"  scope="col"><label for="clientname"></label>
        <select name="clientname" class="ablks1" id="clientname">
          <option value="">Select ClientCode - ClientName</option>
          <?php

	  $result = mysql_query("SELECT clientCode, clientSerial, clientName, clientContactName FROM client where companySerial = '$id' AND clientStatus='1'");
		//echo $result."ll";
   		while($row = mysql_fetch_array($result , MYSQL_ASSOC))
  		{
			$clientSerial = $row["clientSerial"];		
			if($client_id==$clientSerial){
		echo "<option selected='selected' value='$clientSerial'>".$row["clientCode"]." - ".$row["clientName"]."</option>";
			}
		else
		{  		 
  		 echo "<option value='$clientSerial'>".$row["clientCode"]." - ".$row["clientName"]."</option>";
		}
		}	  
	  ?>
      </select></th>
      <th width="8%" align="left" valign="middle"  scope="col">Name of Brief*:</th>
      <th width="27%" align="left" valign="middle"  scope="col"><label for="briefname"></label>
      <input name="briefname" type="text" class="ablks1" id="briefname" size="30" value="<?php echo $brief_name;?>" /></th>
    </tr>
    <tr class="ablks1">
      <th align="left" valign="middle" scope="col">Type of Brief*: </th>
      <th align="left" valign="middle"  scope="col"><select name="brieftype" class="ablks1" id="brieftype">
        <option value="Client Brief"<?php if($brief_type=="Client Brief"){?> selected="selected"<?php }?>>Client Brief</option>
        <option value="Design Brief"<?php if($brief_type=="Design Brief"){?> selected="selected"<?php }?>>Design Brief</option>
        </select></th>
      <th align="left" valign="middle"  scope="col">Create*:</th>
      <th align="left" valign="middle"  scope="col"><label for="brieffrom">
        <select name="brieffrom" class="ablks1" id="brieffrom">
          <option value="From Scratch"<?php if($brief_create=="From Scratch"){?> selected="selected"<?php }?>>From Scratch</option>
          <option value="From another Brief"<?php if($brief_create=="From another Brief"){?> selected="selected"<?php }?>>From another Brief</option>
          </select>
      </label></th>
      <th align="left" valign="middle" scope="col">Copy from:</th>
      <th align="left" valign="middle"  scope="col"><select name="brieflist" class="ablks1" id="brieflist">
        <option value="Design Brief - xyz"<?php if($brief_copy_from=="Design Brief - xyz"){?> selected="selected"<?php }?>>Design Brief - xyz</option>
        <option value="Design Brief - abc"<?php if($brief_copy_from=="Design Brief - abc"){?> selected="selected"<?php }?>>Design Brief - abc</option>
        <option value="Client Brief - 123"<?php if($brief_copy_from=="Client Brief - 123"){?> selected="selected"<?php }?>>Client Brief - 123</option>
      </select> <input type="image" src="../images/icon-save.png"  width="15" height="15" border="0"  /></th>
    </tr>
    <tr class="ablks1">
      <th align="left" valign="top" scope="col">&nbsp;</th>
      <th colspan="5" align="left" valign="top" >&nbsp;</th>
    </tr>
    <tr class="ablks1">
      <th colspan="6" align="left" valign="top" scope="col"><hr /></th>
    </tr>
  </table>
</form>
<br />
<?php } }?>

  <img src="../images/icon-heading.gif" width="12" height="13" /> <span class="lbrownlll7">List of Active Briefs</span><br />
  <br />

<table class="table1" width="100%" border="0">
  <tr class="fbrownl7">
    <td width="8%"  align="left" valign="top" bgcolor="#E2E2E2" scope="col">Date Created<br />
      (yyyy.mm.dd)
      </th></td>
    <td width="11%" align="left" valign="top" bgcolor="#E2E2E2" scope="col">Brief From/<br />
      ID/ Rev</td>
    <td width="31%" align="left" valign="top" bgcolor="#E2E2E2" scope="col">Brief Name<br />
      Project      Name/ 
    Client Name</td>
    <td width="6%" align="left" valign="top" bgcolor="#E2E2E2" scope="col">Brief <br />
      Type <?php if($order_type=="ASC"){?><a href="Brief.php?otype=DESC&amp;opar=brief_type"><img src="../images/icon-up.png" alt="" width="12" height="8" border="0"/></a>
    <?php }else { ?><a href="Brief.php?otype=ASC&amp;opar=brief_type"><img src="../images/icon-down.png" alt="" width="12" height="8" border="0"/></a>
    <?php }?></td>
    <td width="18%" align="left" valign="top" bgcolor="#E2E2E2" scope="col">Developed<br />
      By</td>
    <td width="14%" align="left" valign="top" bgcolor="#E2E2E2" scope="col">Status/<br />
      Cycle</td>
    <td width="12%" align="right" valign="top" bgcolor="#E2E2E2" scope="col"> Start/ Edit/ Del<br />
      View/  Hide/ Lock</td>
  </tr>
   <?php
		 $result = mysql_query("SELECT brief.creationDate, brief.brief_create_from,brief.brief_id,brief.brief_name,brief.brief_type,brief.PreparedBy,brief.companyID,projects.projectName,client.clientName FROM projects,client,brief where brief.companyID='$id' AND brief.brief_status='1' AND projects.projectSerial=brief.project_id AND client.clientSerial=brief.client_id  ORDER BY $order_par $order_type");
   		while($row = mysql_fetch_array($result , MYSQL_ASSOC))
  		{
			$PreparedBy = "";
  		 if($row["PreparedBy"]==$row["companyID"]){
			$resultPre = mysql_query("SELECT firstName, lastName FROM login where loginId='".$row["PreparedBy"]."'"); 
			$PreparedBy .= mysql_result($resultPre,0,0);
			$PreparedBy .=" ". mysql_result($resultPre,0,1);
		 }
		 else{
			 $resultPre = mysql_query("SELECT internal_personnel_firstName, internal_personnel_lastName FROM internal_personnel where internal_personnel_id='".$row["PreparedBy"]."'"); 
			 $PreparedBy .= mysql_result($resultPre,0,0);
			 $PreparedBy .=" ". mysql_result($resultPre,0,1);
		 }
  		?>
  <tr class="ablks1">
    <td align="left" valign="top" class="ablks1" scope="col"><?php echo $row["creationDate"]; ?></td>
    <td align="left" valign="top" class="ablks1"><?php echo $row["brief_create_from"]; ?><br />
      BRF-<?php echo $row["brief_id"]; ?><br />
      0</td>
    <td align="left" valign="top" class="ablks1"><?php echo $row["brief_name"]; ?><br /><?php echo $row["projectName"]."/ ".$row["clientName"]; ?></td>
    <td align="left" valign="top" class="ablks1"><?php echo $row["brief_type"]; ?></td>
    <td align="left" valign="top" class="ablks1">Prepared By:<?php echo $PreparedBy;?><br />
      Reviewed By:<br />
      Consolidated By:</td>
    <td align="left" valign="top" class="ablks1">Sent for Review</td>
    <td align="right" valign="top">&nbsp;<a href="Brief-C1.php?BID=<?php echo $row["brief_id"]; ?>"><img src="../images/icon-writing.jpg" width="15" height="16" border="0" /></a>
    <?php if ($uacc == "Full Control") {?><a href="Brief.php?Edit=<?php echo $row["brief_id"]; ?>"><img src="../images/icon-edit1.png" width="15" height="15" border="0" alt="Edit"  title="Edit" /></a><?php } else { ?><img src="../images/icon-edit1.png" width="15" height="15" border="0" alt="Edit"  title="Edit" /><?php } ?>
     <?php if ($uacc == "Full Control") {?>
      <a href="BriefDB.php?del=<?php echo $row["brief_id"]; ?>" onclick="return confirm('This record will be deleted and cannot be retrieved. Press OK to Delete.')"><img src="../images/icon-del1.png" width="16" height="16" border="0" alt="Delete"  title="Delete" /></a><?php } else { ?><img src="../images/icon-del1.png" width="16" height="16" border="0" alt="Delete"  title="Delete" /><?php } ?>
     <br />
      <a href="Brief-C1PV.php?BID=<?php echo $row["brief_id"]; ?>"> <img src="../images/icon-PV3.png" width="14" height="14" border="0" /></a> <?php if ($uacc == "Full Control") {?><a href="BriefDB.php?InActive=<?php echo $row['brief_id']; ?>"><img src="../images/icon-hide.gif" width="20" height="14" title="Hide" alt="Hide" border="0" /></a><?php } else { ?><img src="../images/icon-hide.gif" width="20" height="14" title="Hide" alt="Hide" border="0" /><?php }?> <img src="../images/icon-lock.png" width="12" height="17" border="0" /></td>
  </tr>
  <?php }?>
</table>
<br />
<br />
<br />
<hr />
<p><img src="../images/icon-warn2.png" width="17" height="17" border="0" /><br />
  1. 
  Deletion is permanent and can not be retrieved. <br />
  2. If a  parameter has been used at other places, deletion might cause problems. <br />
  3. A 
  parameter can be deleted only after its usage is removed from other places. <br />
  4. 
  If you dont want to see an entry or a parameter in the list, you can hide it instead of deleting it. <br />
  5. A Hidden entry or parameter will  show as &quot;HIDDEN&quot; at all places where it was used before. <br />
  6. A Brief can be sent for review from the Brief Development window and will show in the drop down for assigning documents for review to MyTeam. <br />
</p>
<br />
  <br />
  <img src="../images/icon-info1.png" width="17" height="17" border="0" /> List of Hidden Briefs
<table class="table1" width="100%" border="0">
  <tr class="ablks1">
    <td width="8%"  align="left" valign="top" bgcolor="#E2E2E2" scope="col">Date Created<br />
      (yyyy.mm.dd)
      </th></td>
    <td width="11%" align="left" valign="top" bgcolor="#E2E2E2" scope="col">Brief From/<br />
      ID/ Rev</td>
    <td width="31%" align="left" valign="top" bgcolor="#E2E2E2" scope="col">Brief Name<br />
      Project      Name/ 
      Client Name</td>
    <td width="6%" align="left" valign="top" bgcolor="#E2E2E2" scope="col">Brief <br />
      Type <?php if($order_type=="ASC"){?><a href="Brief.php?otype=DESC&amp;opar=brief_type"><img src="../images/icon-up.png" alt="" width="12" height="8" border="0"/></a>
    <?php }else { ?><a href="Brief.php?otype=ASC&amp;opar=brief_type"><img src="../images/icon-down.png" alt="" width="12" height="8" border="0"/></a>
    <?php }?></td>
    <td width="18%" align="left" valign="top" bgcolor="#E2E2E2" scope="col">Developed<br />
      By</td>
    <td width="14%" align="left" valign="top" bgcolor="#E2E2E2" scope="col">Status</td>
    <td width="12%" align="right" valign="top" bgcolor="#E2E2E2" scope="col">Unhide</td>
  </tr>
  <?php
		 $result = mysql_query("SELECT brief.creationDate, brief.brief_create_from,brief.brief_id,brief.brief_name,brief.brief_type,brief.PreparedBy,brief.companyID,projects.projectName,client.clientName FROM projects,client,brief where brief.companyID='$id' AND brief.brief_status='0' AND projects.projectSerial=brief.project_id AND client.clientSerial=brief.client_id  ORDER BY $order_par $order_type");
   		while($row = mysql_fetch_array($result , MYSQL_ASSOC))
  		{
			$PreparedBy = "";
  		 if($row["PreparedBy"]==$row["companyID"]){
			$resultPre = mysql_query("SELECT firstName, lastName FROM login where loginId='".$row["PreparedBy"]."'"); 
			$PreparedBy .= mysql_result($resultPre,0,0);
			$PreparedBy .=" ". mysql_result($resultPre,0,1);
		 }
		 else{
			 $resultPre = mysql_query("SELECT internal_personnel_firstName, internal_personnel_lastName FROM internal_personnel where internal_personnel_id='".$row["PreparedBy"]."'"); 
			 $PreparedBy .= mysql_result($resultPre,0,0);
			 $PreparedBy .=" ". mysql_result($resultPre,0,1);
		 }
  		?>
  <tr class="ablks1">
    <td align="left" valign="top" class="ablks1" scope="col"><?php echo $row["creationDate"]; ?></td>
    <td align="left" valign="top" class="ablks1"><?php echo $row["brief_create_from"]; ?><br />
      BRF-<?php echo $row["brief_id"]; ?><br />
      0</td>
    <td align="left" valign="top" class="ablks1"><?php echo $row["brief_name"]; ?><br /><?php echo $row["projectName"]."/ ".$row["clientName"]; ?></td>
    <td align="left" valign="top" class="ablks1"><?php echo $row["brief_type"]; ?></td>
    <td align="left" valign="top" class="ablks1">Prepared By:<?php echo $PreparedBy;?><br />
      Reviewed By:<br />
      Consolidated By:</td>
    <td align="left" valign="top" class="ablks1">Sent for Review</td>
    <td align="right" valign="top"><?php if ($uacc == "Full Control") {?>
      <a href="BriefDB.php?Active=<?php echo $row['brief_id']; ?>"><img src="../images/icon-look.jpg" width="22" height="14" title="Active" alt="Active" border="0"/>
      </a>
      <?php } else {?>
      <img src="../images/icon-look.jpg" width="22" height="14" title="Active" alt="Active" border="0"/>
      <?php } ?></td>
  </tr>
  <?php }?>
</table>
<p>  <br />
</p>
<?php include('../includes/footer.php');?>