示例#1
0
    public function action_load_contacts_table()
    {
        $page = $_REQUEST["page"];
        $pagelength = isset($_REQUEST["pl"]) ? $_REQUEST["pl"] : 10;
        $sort = $_REQUEST["sort"];
        $query = $_REQUEST["f"];
        $tag = $_REQUEST["tag"];
        $letter = $_REQUEST["letter"];
        $dept = $_REQUEST["dept"];
        $Directory = new DirectoryObj();
        $start = ($page - 1) * $pagelength;
        $finish = $start + $pagelength;
        if (isset($sort)) {
            switch ($sort) {
                case "name":
                    $orderby = "C.lastname ASC, C.firstname ASC";
                    break;
                case "name_r":
                    $orderby = "C.lastname DESC, C.firstname DESC";
                    break;
                default:
                    $orderby = "";
            }
        }
        if ($query != "" or $tag != "" or $letter != "" or $dept != "") {
            $contacts = $Directory->filter_contacts($query, $start >= 0 ? $start : 0, $pagelength, $orderby, $tag, $letter, $dept);
            $contact_count = $Directory->count_contacts($query, $tag, $letter, $dept);
        } else {
            $contacts = $Directory->load_contacts($start >= 0 ? $start : 0, $pagelength, $orderby);
            $contact_count = $Directory->count_contacts();
        }
        if ($finish > $contact_count) {
            $finish = $contact_count;
        }
        ob_start();
        ?>
			<div class="contacts-table">
			<table cellpadding="0" cellspacing="0">
				<thead>
					<tr>
						<th class="first check"></th>
						<th class="name<?php 
        echo ($sort == "name" or $sort == "name_r") ? " current" : "";
        ?>
">
							<a href="#" sort="name<?php 
        echo $sort == "name" ? "_r" : "";
        ?>
" class="sort<?php 
        echo ($sort == "name" or $sort == "name_r") ? " current" : "";
        echo $sort == "name" ? " descending" : " ascending";
        ?>
" title="Contact name">Name</a>
						</th>
						<th class="department">
							<a href="#" sort="department" title="Department name">Department</a>
						</th>
						<th class="position">
							<a href="#" sort="position" title="Position name">Position</a>
						</th>
						<th class="email">
							<a href="#" sort="email" title="Email">Email</a>
						</th>
						<th class="last edit"></th>
					</tr>
				</thead>
				<tbody>
					<?php 
        if (count($contacts) > 0) {
            ?>
					<?php 
            foreach ($contacts as $contact) {
                if (!$contact->loaded) {
                    continue;
                }
                ?>
					<tr cid="<?php 
                echo $contact->cid;
                ?>
" ctype="person">
						<td class="check"><input class="contact_checked" type="checkbox" value="<?php 
                echo $contact->cid;
                ?>
" /></td>
						<td class="name" cid="<?php 
                echo $contact->cid;
                ?>
">
							<div class="box">
								<a href="<?php 
                echo Yii::app()->createUrl('contact');
                ?>
?cid=<?php 
                echo $contact->cid;
                ?>
" class="view-contact" title="<?php 
                echo @$contact->tags;
                ?>
"><?php 
                echo @$contact->lastname . ", " . @$contact->firstname;
                ?>
</a>
								<?php 
                if (!Yii::app()->user->isGuest) {
                    ?>
<a href="#" title="Edit" class="se edit-name"></a><?php 
                }
                ?>
							</div>
						</td>
						<td class="department">
							<div class="box">
								<a href="<?php 
                echo Yii::app()->createUrl('dept');
                ?>
?deptid=<?php 
                echo @$contact->get_primary_department()->deptid;
                ?>
"><?php 
                echo @$contact->get_primary_department()->deptname;
                ?>
</a>
							</div>
						</td>
						<td class="position">
							<div class="box">
								<?php 
                echo @$contact->get_primary_position()->posname;
                ?>
							</div>
						</td>
						<td class="email">
							<div class="box">
								<?php 
                echo strtolower($contact->email);
                ?>
							</div>
						</td>
						<td class="edit">
							<a class="delete" href="#delete" title="Delete this person">Delete</a>
						</td>
					</tr>
					<?php 
            }
            ?>
					<?php 
        } else {
            ?>
					<tr>
						<td colspan="5">
							<div class="empty-table">
								No contacts found. Click <a href="<?php 
            echo Yii::app()->createUrl('index');
            ?>
">here</a> to view all contacts.
							</div>
						</td>
					</tr>
					
					<?php 
        }
        ?>
				</tbody>
			</table>
		</div>
	</div>
		<?php 
        $contents = ob_get_contents();
        ob_end_clean();
        ob_start();
        ?>
			<?php 
        if ($start == 0) {
            ?>
				<span class="disabled first_page">First</span>
				<span class="disabled prev_page">Prev</span>
			<?php 
        } else {
            ?>
				<a href="#" class="first_page">First</a>
				<a href="#" class="prev_page">Prev</a>
			<?php 
        }
        ?>
			
			<span class="counts current"><?php 
        echo $start;
        ?>
-<?php 
        echo $finish;
        ?>
 of <?php 
        echo $contact_count;
        ?>
</span>
			
			<?php 
        if ($finish == $contact_count) {
            ?>
				<span class="disabled next_page">Next</span>
				<span class="disabled last_page">Last</span>
			<?php 
        } else {
            ?>
				<a href="#" class="next_page">Next</a>
				<a href="#" class="last_page">Last</a>
			<?php 
        }
        ?>
		
		<?php 
        $paging = ob_get_contents();
        ob_end_clean();
        $return = array();
        $return["contents"] = $contents;
        $return["paging"] = $paging;
        $return["start"] = $start;
        $return["finish"] = $finish;
        $return["total"] = $contact_count;
        $return["ended"] = $finish == $contact_count;
        print json_encode($return);
        return;
    }