Location: PHPKode > projects > Silicon Fodder > SiliconFodder/DocumentRoot/diary/mulUsers.php
<? require_once("../common/nocache.php"); ?>
<? require_once("../common/appobjects.php"); ?>
<? require_once("../common/db.php"); ?>
<? require_once("../util/general.php"); ?>
<?
if($HTTP_POST_VARS["posted"] == "1") {
	$userSel = $HTTP_POST_VARS["userSel"];
	$linkedFromMessages = $HTTP_POST_VARS["msg"];
	if($userSel != "") {
		// Have we selected all users?
		$noOfUsersSelected = count($userSel);

		$mySQL = "SELECT COUNT(*) AS myCount FROM users WHERE owneruserid=0 AND isDeleted=0 AND isClientContact=0 AND isSuperUser=0 AND isBusCentreAdmin=0 AND companyId=".$myCompId;
		$rows = gendb_query($mySQL, $myDb) or die(gendb_error());
		$row = gendb_fetch_assoc($rows);
		$noOfUsersInDb = $row["myCount"];
		gendb_free_result($rows);

		if($noOfUsersSelected == $noOfUsersInDb) {
			$userSel = "all";
		} else {
			$userSel = implode(",",$userSel);
		}
		
		// Get list of names
		$nameList = "";
		if($noOfUsersSelected == $noOfUsersInDb) {
			$mySQL = "SELECT firstname, lastname FROM users WHERE owneruserid=0 AND isDeleted=0 AND isClientContact=0 AND isSuperUser=0 AND isBusCentreAdmin=0 AND companyId=".$myCompId;
		} else {
			$mySQL = "SELECT firstname, lastname FROM users WHERE id IN (".$userSel.") ORDER BY firstname, lastname";
		}
		$rows = gendb_query($mySQL, $myDb) or die(gendb_error());
		while($row = gendb_fetch_assoc($rows)) {
			if($nameList == "") {
				$nameList.= $row["firstname"]." ".$row["lastname"];
			} else {
				$nameList.= ", ".$row["firstname"]." ".$row["lastname"];
			}
		}
		gendb_free_result($rows);
		$nameList = ereg_replace("'", "&#39;", $nameList);
		$nameList = getShortenedString($nameList, 50);
		
	}
?>
	<html>
	<head>
	<script language="javascript">
	opener.diaryEventHasBeenChanged = true;
	opener.document.frm.mulUsersCsv.value = '<?=$userSel?>';
<?
// if we're adding people for messaging, then update the field that contains the list of names
if($linkedFromMessages == "true") {
?>
	opener.document.getElementById('nameList').innerHTML = '<?=$nameList?>';
<?
}
?>
	self.close();
	</script>
	</head>
	</html>
<?
	exit;
}

$mcsv = $HTTP_GET_VARS["mcsv"];
$linkedFromMessages = $HTTP_GET_VARS["msg"];
$meeting = $HTTP_GET_VARS["meeting"]; //'true' if clicking on 'attendees' in a meeting
$linkedId = $HTTP_GET_VARS["linkedId"];
$userids = $HTTP_GET_VARS["userids"]; // if the diary is viewing for multiple internal user ids
$task = $HTTP_GET_VARS["task"]; // if this is a task, can only select one person (radio buttons, not check)
?>
<html>
<head>
<title>My Web Office</title>
<style>
<? require_once("../common/Lite.php"); ?>
body {
	background-color: #FFFFD5;
}
.month {
	background-color: #9EBEF5;
	font-weight: bold;
	height:40px;
}
.day {
	border-bottom: 1px solid #000000;
}
td,div {
	color: #000000;
	font-size: 8pt;
	font-family: Verdana, Arial, Helvetica;
	padding-left:15px;
	padding-right:15px;
}
th {
	color: #000000;
	font-size: 8pt;
	font-family: Verdana, Arial, Helvetica;
	padding-right:20px;
}
.thisWeek {
	background-color: #FBE694;
}
.week {
	cursor: pointer;
}
a {
	color: <?=getApplicationObject("LINK_COLOUR")?>;
	text-decoration: none;
}
</style>
<script language="javascript">
function setImgSrc(imageName, imageLocation) {
	if (document.images) document.images[imageName].src = imageLocation;
	return true;
}
function tickAll() {
	size = frm.length;
	for (i = 0; i < size; i++) {
		frm[i].checked = true;
	}	
}
</script>
</head>
<body style="padding:0px;margin:0px" onBlur="focus()">

<form name="frm" method="post" action="mulUsers.php">
<table cellpadding="1" cellspacing="0" width="100%" border="0">
<tr><td class="month" colspan="2" style="background-image:url('/images/myofficeSml.jpg');background-repeat:no-repeat;background-position: right">Add Multiple Users
&nbsp;
</td></tr>
<tr><th><br>User</th><th align="center"><br><?=($meeting == "true" ? "Status" : "Add?")?></th></tr>
<?
if($meeting == "true") {
	$mySQL = "SELECT firstname, lastname, meetingstatus, addedBy, users.id AS userid FROM users, diary WHERE users.id=diary.userId AND diary.linkedId=".$linkedId." AND users.isDeleted=0 AND diary.isDeleted=0 ORDER BY firstname, lastname";
} elseif($linkedFromMessages == "true") {
	$mySQL = "SELECT * FROM users WHERE users.owneruserid=0 AND isDeleted=0 AND isClientContact=0 AND isSuperUser=0 AND isBusCentreAdmin=0 AND companyId=".$myCompId." AND id!=".$HTTP_SESSION_VARS["mwoid"]." ORDER BY firstname, lastname";
} elseif($userids != "") {
	$mySQL = $mySQL = "SELECT * FROM users WHERE users.owneruserid=0 AND isDeleted=0 AND isClientContact=0 AND isSuperUser=0 AND isBusCentreAdmin=0 AND companyId=".$myCompId." AND id IN (".$userids.") ORDER BY firstname, lastname";
} else {
	if($HTTP_SESSION_VARS["is-smart"] != "true") {
		$mySQL = "SELECT * FROM users WHERE users.owneruserid=0 AND isDeleted=0 AND isClientContact=0 AND isSuperUser=0 AND isBusCentreAdmin=0 AND companyId=".$myCompId." ORDER BY firstname, lastname";
	} else {
		$smartdbs = array("ballinger", "smart", "clarendons");
		$mySQL = "";
		foreach($smartdbs as $smartdb) {
			$mySQL.= ($smartdb == "ballinger" ? "" : " UNION ")."SELECT '".$smartdb."' AS smartdb, users.* FROM ".$smartdb.".users WHERE users.owneruserid=0 AND isDeleted=0 AND isClientContact=0 AND isSuperUser=0 AND isBusCentreAdmin=0 AND companyId=".$myCompId;
		}
		$mySQL.= " ORDER BY firstname, lastname";
	}
}
$rows = gendb_query($mySQL, $myDb) or die(gendb_error());
while($row = gendb_fetch_assoc($rows)) {
	echo "<tr><td>".$row["firstname"]." ".$row["lastname"]."</td><td align=\"center\">";
	if($meeting == "true" && $row["addedBy"] == $row["userid"]) {
		echo "Meeting originator</td></tr>";
	} elseif($meeting == "true" && $row["meetingstatus"] == 0) {
		echo "No reply</td></tr>";
	} elseif($meeting == "true" && $row["meetingstatus"] == 1) {
		echo "Attending</td></tr>";
	} elseif($meeting == "true" && $row["meetingstatus"] == 2) {
		echo "Declined</td></tr>";
	} elseif($mcsv != "all" && strpos(",".$mcsv.",", ",".$row["id"].",") === false) {
		if($task == "997" || $task == "996") {
			echo "<input type=\"radio\" name=\"userSel[]\" value=\"".$row["smartdb"].$row["id"]."\"></td></tr>";
		} else {
			echo "<input type=\"checkbox\" name=\"userSel[]\" value=\"".$row["smartdb"].$row["id"]."\"></td></tr>";
		}
	} else {
		if($task == "997" || $task == "996") {
			echo "<input type=\"radio\" checked name=\"userSel[]\" value=\"".$row["smartdb"].$row["id"]."\"></td></tr>";
		} else {
			echo "<input type=\"checkbox\" checked name=\"userSel[]\" value=\"".$row["smartdb"].$row["id"]."\"></td></tr>";
		}
	}
}
gendb_free_result($rows);

?>
<? if($meeting != "true") { ?>
<tr><td>&nbsp;</td><td align="right"><a onClick="tickAll();return false;" style="position:relative;right:20px" href="">[select all]</a></td></tr>
<? } ?>
<tr><td colspan="2"><hr></td></tr>
<tr><td colspan="2" align="right"><br>
<? if($meeting == "true") { ?>
<?=displayCloseButton("Close", "self.close()")?>
<? } else { ?>
<?=displayAddUsersButton("Add", "document.frm.submit()")?>
<? } ?>
<br>&nbsp;</td></tr>
</table>
<input type="hidden" name="posted" value="1">
<input type="hidden" name="msg" value="<?=$linkedFromMessages?>">
</form>
</body>
</html>
Return current item: Silicon Fodder