summaryrefslogtreecommitdiff
path: root/demos/time-tracker/protected
diff options
context:
space:
mode:
authorwei <>2006-07-18 23:39:13 +0000
committerwei <>2006-07-18 23:39:13 +0000
commit2fbc53d1f5d9e0a000717642d02558453bc610a8 (patch)
tree0ab6b464cf6b319f862e075ddd442558971c5aa6 /demos/time-tracker/protected
parent319df8f534520c8c926d0cdaa1f5577c7bd8a909 (diff)
Add more tests and business code for time-tracker
Diffstat (limited to 'demos/time-tracker/protected')
-rw-r--r--demos/time-tracker/protected/App_Code/Category.php13
-rw-r--r--demos/time-tracker/protected/App_Code/CategoryDao.php50
-rw-r--r--demos/time-tracker/protected/App_Code/DaoManager.php2
-rw-r--r--demos/time-tracker/protected/App_Code/DateTimeMySQL.php33
-rw-r--r--demos/time-tracker/protected/App_Code/Project.php2
-rw-r--r--demos/time-tracker/protected/App_Code/ProjectDao.php115
-rw-r--r--demos/time-tracker/protected/App_Code/TimeEntry.php16
-rw-r--r--demos/time-tracker/protected/App_Code/TimeEntryDao.php47
-rw-r--r--demos/time-tracker/protected/App_Code/UserDao.php10
-rw-r--r--demos/time-tracker/protected/App_Code/UserReport.php10
-rw-r--r--demos/time-tracker/protected/App_Code/UserReportsDao.php25
-rw-r--r--demos/time-tracker/protected/App_Data/mysql-sqlmap.xml14
-rw-r--r--demos/time-tracker/protected/App_Data/users.xml133
-rw-r--r--demos/time-tracker/protected/application.xml3
-rw-r--r--demos/time-tracker/protected/pages/TimeTracker/SiteMap.php2
-rw-r--r--demos/time-tracker/protected/pages/TimeTracker/UserCreate.page136
-rw-r--r--demos/time-tracker/protected/pages/TimeTracker/UserCreate.php64
-rw-r--r--demos/time-tracker/protected/pages/TimeTracker/UserList.page30
-rw-r--r--demos/time-tracker/protected/pages/TimeTracker/UserList.php34
19 files changed, 464 insertions, 275 deletions
diff --git a/demos/time-tracker/protected/App_Code/Category.php b/demos/time-tracker/protected/App_Code/Category.php
new file mode 100644
index 00000000..9bdedb5f
--- /dev/null
+++ b/demos/time-tracker/protected/App_Code/Category.php
@@ -0,0 +1,13 @@
+<?php
+
+class Category
+{
+ public $ActualDuration = 0.0;
+ public $Abbreviation = '';
+ public $ID=0;
+ public $EstimateDuration = 0.0;
+ public $Name='';
+ public $ProjectID=0;
+}
+
+?> \ No newline at end of file
diff --git a/demos/time-tracker/protected/App_Code/CategoryDao.php b/demos/time-tracker/protected/App_Code/CategoryDao.php
new file mode 100644
index 00000000..f0149f0b
--- /dev/null
+++ b/demos/time-tracker/protected/App_Code/CategoryDao.php
@@ -0,0 +1,50 @@
+<?php
+
+class CategoryDao extends BaseDao
+{
+ function addNewCategory($category)
+ {
+ $sqlmap = $this->getConnection();
+ $sqlmap->insert('AddNewCategory', $category);
+ }
+
+ function getCategoryByID($categoryID)
+ {
+ $sqlmap = $this->getConnection();
+ return $sqlmap->queryForObject('GetCategoryByID', $categoryID);
+ }
+
+ function getAllCategories()
+ {
+ $sqlmap = $this->getConnection();
+ return $sqlmap->queryForList('GetAllCategories');
+ }
+
+ function deleteCategory($categoryID)
+ {
+ $sqlmap = $this->getConnection();
+ $sqlmap->delete('DeleteCategory', $categoryID);
+ }
+
+ function getCategoriesByProjectID($projectID)
+ {
+ $sqlmap = $this->getConnection();
+ return $sqlmap->queryForList('GetCategoriesByProjectID', $projectID);
+ }
+
+ function getCategoryByNameInProject($name, $projectID)
+ {
+ $sqlmap = $this->getConnection();
+ $param['project'] = $projectID;
+ $param['category'] = $name;
+ return $sqlmap->queryForObject('GetCategoryByNameInProject', $param);
+ }
+
+ function updateCategory($category)
+ {
+ $sqlmap = $this->getConnection();
+ $sqlmap->update('UpdateCategory', $category);
+ }
+}
+
+?> \ No newline at end of file
diff --git a/demos/time-tracker/protected/App_Code/DaoManager.php b/demos/time-tracker/protected/App_Code/DaoManager.php
index b8ac55af..ac546054 100644
--- a/demos/time-tracker/protected/App_Code/DaoManager.php
+++ b/demos/time-tracker/protected/App_Code/DaoManager.php
@@ -98,7 +98,7 @@ class DaoManager extends TModule
return $this->_dao[$class]['instance'];
}
else
- throw TimeTrackerException('daomanager_undefined_dao', $class);
+ throw new TimeTrackerException('daomanager_undefined_dao', $class);
}
/**
diff --git a/demos/time-tracker/protected/App_Code/DateTimeMySQL.php b/demos/time-tracker/protected/App_Code/DateTimeMySQL.php
new file mode 100644
index 00000000..19f41c03
--- /dev/null
+++ b/demos/time-tracker/protected/App_Code/DateTimeMySQL.php
@@ -0,0 +1,33 @@
+<?php
+
+class DateTimeMySQL implements ITypeHandlerCallback
+{
+ /**
+ * Not implemented.
+ */
+ public function getParameter($integer)
+ {
+ return date('Y-m-d H:i:s', $integer);
+ }
+
+ /**
+ * Not implemented.
+ */
+ public function getResult($string)
+ {
+ return strtotime($string);
+ }
+
+ /**
+ * Creates a new instance of TimeTrackerUser
+ * @param array result data
+ * @return TimeTrackerUser new user instance
+ */
+ public function createNewInstance($row=null)
+ {
+ throw new TimeTrackerException('Not implemented');
+ }
+
+}
+
+?> \ No newline at end of file
diff --git a/demos/time-tracker/protected/App_Code/Project.php b/demos/time-tracker/protected/App_Code/Project.php
index 660fad04..bd9c858b 100644
--- a/demos/time-tracker/protected/App_Code/Project.php
+++ b/demos/time-tracker/protected/App_Code/Project.php
@@ -25,7 +25,7 @@ class Project
public $CompletionDate = 0;
public $DateCreated = 0;
public $Description = '';
- public $EstimateDuration = 0;
+ public $EstimateDuration = 0.0;
public $ID = 0;
public $ManagerUserName = '';
public $Name = '';
diff --git a/demos/time-tracker/protected/App_Code/ProjectDao.php b/demos/time-tracker/protected/App_Code/ProjectDao.php
index 81902e0c..416c6540 100644
--- a/demos/time-tracker/protected/App_Code/ProjectDao.php
+++ b/demos/time-tracker/protected/App_Code/ProjectDao.php
@@ -20,32 +20,17 @@
*/
class ProjectDao extends BaseDao
{
-/* public function createNewProject($project)
+ public function projectNameExists($projectName)
{
$sqlmap = $this->getConnection();
- $creator = $sqlmap->queryForObject('GetUserByName', $project->CreatorUserName);
- $manager = $sqlmap->queryForObject('GetUserByName', $project->ManagerUserName);
- $exists = $sqlmap->queryForObject('GetProjectByName', $project->Name);
- if($exists)
- {
- throw new TimeTrackerException(
- 'project_exists', $project->Name);
- }
- else if(!$creator || !$manager)
- {
- throw new TimeTrackerException(
- 'invalid_creator_and_manager',
- $project->Name, $project->CreatorUserName,
- $project->ManagerUserName);
- }
- else
- {
- $param['project'] = $project;
- $param['creator'] = $creator->ID;
- $param['manager'] = $manager->ID;
- return $sqlmap->insert('CreateNewProject', $param);
- }
- }
+ return $sqlmap->queryForObject('ProjectNameExists', $projectName);
+ }
+
+ public function addNewProject($project)
+ {
+ $sqlmap = $this->getConnection();
+ $sqlmap->insert('CreateNewProject', $project);
+ }
public function getProjectByID($projectID)
{
@@ -53,41 +38,61 @@ class ProjectDao extends BaseDao
return $sqlmap->queryForObject('GetProjectByID', $projectID);
}
- public function addUserToProject($project, $user)
+ public function deleteProject($projectID)
{
$sqlmap = $this->getConnection();
- $project = $this->getProjectByID($project->ID);
- $user = $sqlmap->queryForObject('GetUserByName', $user->Name);
- $list = $sqlmap->queryForList('GetProjectMembers', $project);
- $userExists = false;
- foreach($list as $k)
- {
- if($k->ID == $user->ID)
- $userExists = true;
- }
- if(!$project)
- {
- throw new TimeTrackerException(
- 'invalid_project', $project->Name);
- }
- else if(!$user)
- {
- throw new TimeTrackerException(
- 'invalid_user', $user->Name);
- }
- else if($userExists)
- {
- throw new TimeTrackerException(
- 'project_member_exists', $projet->Name, $user->Name);
- }
- else
+ $sqlmap->update('DeleteProject',$projectID);
+ }
+
+ public function addUserToProject($projectID, $username)
+ {
+ $sqlmap = $this->getConnection();
+ $members = $this->getProjectMembers($projectID);
+ if(!in_array($username, $members))
{
- $param['project'] = $project;
- $param['user'] = $user;
- return $sqlmap->insert('AddUserToProject', $param);
- }
+ $param['username'] = $username;
+ $param['project'] = $projectID;
+ $sqlmap->insert('AddUserToProject',$param);
+ }
+ }
+
+ public function getProjectMembers($projectID)
+ {
+ $sqlmap = $this->getConnection();
+ return $sqlmap->queryForList('GetProjectMembers', $projectID);
+ }
+
+ public function getAllProjects()
+ {
+ $sqlmap = $this->getConnection();
+ return $sqlmap->queryForList('GetAllProjects');
+ }
+
+ public function getProjectsByManagerName($manager)
+ {
+ $sqlmap = $this->getConnection();
+ return $sqlmap->queryForList('GetProjectsByManagerName', $manager);
+ }
+
+ public function getProjectsByUserName($username)
+ {
+ $sqlmap = $this->getConnection();
+ return $sqlmap->queryForList('GetProjectsByUserName', $username);
+ }
+
+ public function removeUserFromProject($projectID, $username)
+ {
+ $sqlmap = $this->getConnection();
+ $param['username'] = $username;
+ $param['project'] = $projectID;
+ $sqlmap->delete('RemoveUserFromProject', $param);
+ }
+
+ public function updateProject($project)
+ {
+ $sqlmap = $this->getConnection();
+ $sqlmap->update('UpdateProject', $project);
}
-*/
}
?> \ No newline at end of file
diff --git a/demos/time-tracker/protected/App_Code/TimeEntry.php b/demos/time-tracker/protected/App_Code/TimeEntry.php
new file mode 100644
index 00000000..e250d67f
--- /dev/null
+++ b/demos/time-tracker/protected/App_Code/TimeEntry.php
@@ -0,0 +1,16 @@
+<?php
+
+class TimeEntry
+{
+ public $CreatorUserName='';
+ public $Category;
+ public $DateCreated=0;
+ public $Description='';
+ public $Duration=0.0;
+ public $ID=0;
+ public $Project;
+ public $ReportDate=0;
+ public $Username;
+}
+
+?> \ No newline at end of file
diff --git a/demos/time-tracker/protected/App_Code/TimeEntryDao.php b/demos/time-tracker/protected/App_Code/TimeEntryDao.php
new file mode 100644
index 00000000..60301f3b
--- /dev/null
+++ b/demos/time-tracker/protected/App_Code/TimeEntryDao.php
@@ -0,0 +1,47 @@
+<?php
+
+class TimeEntryDao extends BaseDao
+{
+ public function addNewTimeEntry($entry)
+ {
+ $sqlmap = $this->getConnection();
+ $sqlmap->insert('AddNewTimeEntry', $entry);
+ }
+
+ public function getTimeEntryByID($entryID)
+ {
+ $sqlmap = $this->getConnection();
+ return $sqlmap->queryForObject('GetTimeEntryByID', $entryID);
+ }
+
+ public function deleteTimeEntry($entryID)
+ {
+ $sqlmap = $this->getConnection();
+ $sqlmap->delete('DeleteTimeEntry', $entryID);
+ }
+
+ public function getTimeEntriesInProject($username, $projectID)
+ {
+ $sqlmap = $this->getConnection();
+ $param['username'] = $username;
+ $param['project'] = $projectID;
+ return $sqlmap->queryForList('GetAllTimeEntriesByProjectIdAndUser', $param);
+ }
+
+ public function updateTimeEntry($entry)
+ {
+ $sqlmap = $this->getConnection();
+ $sqlmap->update('UpdateTimeEntry', $entry);
+ }
+
+ public function getTimeEntriesByDate($username, $start, $end)
+ {
+ $sqlmap = $this->getConnection();
+ $param['username'] = $username;
+ $param['startDate'] = $start;
+ $param['endDate'] = $end;
+ return $sqlmap->queryForList('GetTimeEntriesByDate', $param);
+ }
+}
+
+?> \ No newline at end of file
diff --git a/demos/time-tracker/protected/App_Code/UserDao.php b/demos/time-tracker/protected/App_Code/UserDao.php
index 4dc39b2b..6064be7e 100644
--- a/demos/time-tracker/protected/App_Code/UserDao.php
+++ b/demos/time-tracker/protected/App_Code/UserDao.php
@@ -34,6 +34,16 @@ class UserDao extends BaseDao
}
/**
+ * @param string username
+ * @return boolean true if username already exists, false otherwise.
+ */
+ public function usernameExists($username)
+ {
+ $sqlmap = $this->getConnection();
+ return $sqlmap->queryForObject('UsernameExists', $username);
+ }
+
+ /**
* @return array list of all enabled users.
*/
public function getAllUsers()
diff --git a/demos/time-tracker/protected/App_Code/UserReport.php b/demos/time-tracker/protected/App_Code/UserReport.php
new file mode 100644
index 00000000..e7529120
--- /dev/null
+++ b/demos/time-tracker/protected/App_Code/UserReport.php
@@ -0,0 +1,10 @@
+<?php
+
+class UserReport
+{
+ public $Username = '';
+ public $CategoryID = 0;
+ public $ActualDuration = 0.0;
+}
+
+?> \ No newline at end of file
diff --git a/demos/time-tracker/protected/App_Code/UserReportsDao.php b/demos/time-tracker/protected/App_Code/UserReportsDao.php
new file mode 100644
index 00000000..3cf943af
--- /dev/null
+++ b/demos/time-tracker/protected/App_Code/UserReportsDao.php
@@ -0,0 +1,25 @@
+<?php
+
+class UserReportsDao extends BaseDao
+{
+ public function getUserTimeReport($username)
+ {
+ $sqlmap = $this->getConnection();
+ return $sqlmap->queryForObject('GetTimeReportByUsername', $username);
+ }
+
+ public function getTimeReportsByCategoryID($categoryID)
+ {
+ $sqlmap = $this->getConnection();
+ return $sqlmap->queryForList('GetTimeReportByCategoryID', $categoryID);
+ }
+
+ public function getTimeReportsByProjectID($projectID)
+ {
+ $sqlmap = $this->getConnection();
+ return $sqlmap->queryForList('GetTimeReportByProjectID', $projectID);
+ }
+
+}
+
+?> \ No newline at end of file
diff --git a/demos/time-tracker/protected/App_Data/mysql-sqlmap.xml b/demos/time-tracker/protected/App_Data/mysql-sqlmap.xml
index fe4ebedc..3f850955 100644
--- a/demos/time-tracker/protected/App_Data/mysql-sqlmap.xml
+++ b/demos/time-tracker/protected/App_Data/mysql-sqlmap.xml
@@ -1,8 +1,11 @@
<?xml version="1.0" encoding="UTF-8" ?>
<sqlMapConfig>
- <typeHandler type="TimeTrackerUser"
- callback="TimeTrackerUserTypeHandler"/>
+ <typeHandlers>
+ <typeHandler type="TimeTrackerUser"
+ callback="TimeTrackerUserTypeHandler"/>
+ <typeHandler type="DateTime" callback="DateTimeMySQL" />
+ </typeHandlers>
<provider class="TAdodb">
<datasource
@@ -14,8 +17,11 @@
</provider>
<sqlMaps>
- <sqlMap resource="users.xml"/>
- <sqlMap resource="project.xml"/>
+ <sqlMap resource="mysql-maps/users.xml"/>
+ <sqlMap resource="mysql-maps/projects.xml"/>
+ <sqlMap resource="mysql-maps/category.xml" />
+ <sqlMap resource="mysql-maps/time-entry.xml" />
+ <sqlMap resource="mysql-maps/reports.xml" />
</sqlMaps>
</sqlMapConfig> \ No newline at end of file
diff --git a/demos/time-tracker/protected/App_Data/users.xml b/demos/time-tracker/protected/App_Data/users.xml
deleted file mode 100644
index f4151c30..00000000
--- a/demos/time-tracker/protected/App_Data/users.xml
+++ /dev/null
@@ -1,133 +0,0 @@
-<?xml version="1.0" encoding="utf-8" ?>
-<sqlMap>
-
-<resultMap id="time-tracker-user" class="TimeTrackerUser" GroupBy="Name">
- <result property="Name" column="Name" />
- <result property="EmailAddress" column="EmailAddress" />
- <result property="Roles" Type="array" resultMapping="user-roles-result" />
-</resultMap>
-
-<resultMap id="user-roles-result">
- <result column="role" />
-</resultMap>
-
-<!--
-<select id="GetUserByName" parameterClass="string" resultMap="TimeTrackerUser">
- SELECT
- users.Username as Name,
- users.EmailAddress as EmailAddress,
- user_roles.RoleType as role
- FROM
- users
- LEFT JOIN user_roles ON users.Username = user_roles.UserID
- WHERE
- Username = #value#
- AND
- Disabled = 0
-</select>
--->
-
-<select id="GetUserByName" parameterClass="string" resultMap="time-tracker-user">
- SELECT
- users.Username as Name,
- users.EmailAddress as EmailAddress,
- user_roles.RoleType as role
- FROM
- users
- LEFT JOIN user_roles ON users.Username = user_roles.UserID
- WHERE
- Username = #value#
- AND
- Disabled = 0
-</select>
-
-<select id="GetAllUsers" resultMap="time-tracker-user">
- SELECT
- users.Username as Name,
- users.EmailAddress as EmailAddress,
- user_roles.RoleType as role
- FROM
- users
- LEFT JOIN user_roles ON users.Username = user_roles.UserID
- WHERE
- Disabled = 0
-</select>
-
-<select id="ValidateUser" resultClass="boolean">
- SELECT
- count(Username)
- FROM
- users
- WHERE
- username = #username# AND password = #password#
- AND
- Disabled = 0
-</select>
-
-<insert id="AddNewUser" parameterClass="array">
- INSERT INTO
- users (Username, Password, EmailAddress)
- VALUES
- (#user.Name#, #password#, #user.EmailAddress#)
-</insert>
-
-<update id="DeleteUserByName">
- UPDATE users SET Disabled = 1 WHERE username = #value#
-</update>
-
-<insert id="RegisterAutoSignon" parameterClass="array">
- INSERT INTO
- signon (SessionToken, Username, LastSignOnDate)
- VALUES
- (#token#, #username#, NOW())
-</insert>
-
-<select id="ValidateAutoSignon" resultMap="time-tracker-user">
- SELECT
- users.Username as Name,
- users.EmailAddress as EmailAddress,
- user_roles.RoleType as role
- FROM
- users LEFT JOIN user_roles ON users.Username = user_roles.UserID,
- signon
- WHERE
- users.Username = signon.Username
- AND signon.SessionToken = #value#
- AND users.Disabled = 0
-</select>
-
-<update id="UpdateSignon">
- UPDATE signon SET LastSignOnDate = NOW()
- WHERE SessionToken = #value#
-</update>
-
-<delete id="DeleteUserRoles" parameterClass="TimeTrackerUser">
- DELETE FROM user_roles WHERE UserID = #Name#
-</delete>
-
-<update id="AddUserRole" parameterClass="array">
- INSERT INTO user_roles (UserID, RoleType)
- VALUES(#username#, #role#)
-</update>
-
-<update id="UpdateUserDetails" parameterClass="TimeTrackerUser">
- UPDATE users
- SET EmailAddress = #EmailAddress#
- WHERE Username = #Name#
-</update>
-
-<update id="UpdateUserDetailsAndPassword" parameterClass="array">
- UPDATE users
- SET EmailAddress = #user.EmailAddress#, Password=#password#
- WHERE Username = #user.Name#
-</update>
-
-<delete id="DeleteAutoSignon">
- DELETE FROM signon WHERE Username = #value#
-</delete>
-
-<delete id="DeleteAllSignon">
- DELETE FROM signon
-</delete>
-
-</sqlMap> \ No newline at end of file
diff --git a/demos/time-tracker/protected/application.xml b/demos/time-tracker/protected/application.xml
index 801b6eb3..e7d3b330 100644
--- a/demos/time-tracker/protected/application.xml
+++ b/demos/time-tracker/protected/application.xml
@@ -15,6 +15,9 @@
<module id="daos" class="DaoManager" Connection="sqlmap">
<dao id="UserDao" class="Application.App_Code.UserDao" />
<dao id="ProjectDao" class="Application.App_Code.ProjectDao" />
+ <dao id="TimeEntryDao" class="Application.App_Code.TimeEntryDao" />
+ <dao id="CategoryDao" class="Application.App_Code.CategoryDao" />
+ <dao id="ReportDao" class="Application.App_Code.UserReportsDao" />
</module>
</modules>
<services>
diff --git a/demos/time-tracker/protected/pages/TimeTracker/SiteMap.php b/demos/time-tracker/protected/pages/TimeTracker/SiteMap.php
index 1f452894..1beed757 100644
--- a/demos/time-tracker/protected/pages/TimeTracker/SiteMap.php
+++ b/demos/time-tracker/protected/pages/TimeTracker/SiteMap.php
@@ -43,7 +43,7 @@ class SiteMap extends TTemplateControl
case 'ReportResource':
$active = $this->ReportMenu;
break;
- case 'TimeEntry':
+ default:
$active = $this->LogMenu;
break;
}
diff --git a/demos/time-tracker/protected/pages/TimeTracker/UserCreate.page b/demos/time-tracker/protected/pages/TimeTracker/UserCreate.page
index 41d97391..edc22bcd 100644
--- a/demos/time-tracker/protected/pages/TimeTracker/UserCreate.page
+++ b/demos/time-tracker/protected/pages/TimeTracker/UserCreate.page
@@ -2,74 +2,86 @@
<h2>Create New User</h2>
<fieldset class="signup"><legend>User Details</legend>
- <h4>Sign Up for Your New Account</h4>
- <div class="username">
- <com:TLabel ForControl="username" Text="User Name:" />
- <span class="required">*</span>
- <com:TTextBox ID="username" />
- <com:TRequiredFieldValidator
- ControlToValidate="username"
- Display="Dynamic"
- ErrorMessage="Please enter your username."
- ControlCssClass="required-field" />
- <com:TCustomValidator
- ControlToValidate="username"
- Display="Dynamic"
- OnServerValidate="checkUsername" />
- </div>
- <div class="password">
- <com:TLabel ForControl="password" Text="Password:" />
- <span class="required">*</span>
- <com:TTextBox ID="password" TextMode="Password" />
- <com:TRequiredFieldValidator
- ControlToValidate="password"
- Display="Dynamic"
- ErrorMessage="Please enter your password (6 or more characters)."
- ControlCssClass="required-field" />
- <com:TRegularExpressionValidator
- ControlToValidate="password"
- Display="Dynamic"
- RegularExpression="\w{6,}"
- ErrorMessage="Please enter 6 or more characters."
- ControlCssClass="required-field" />
- </div>
- <div class="password">
- <com:TLabel ForControl="password2" Text="Confirm Password:" />
- <span class="required">*</span>
- <com:TTextBox ID="password2" TextMode="Password" />
- <com:TCompareValidator
- ControlToValidate="password"
- ControlToCompare="password2"
- ErrorMessage="The Password and Confirmation Password must match."
- ControlCssClass="required-field" />
- </div>
- <div class="email">
- <com:TLabel ForControl="email" Text="E-Mail Address:" />
- <span class="required">*</span>
- <com:TTextBox ID="email" Style="width:20em"/>
- <com:TRequiredFieldValidator
- ControlToValidate="email"
- Display="Dynamic"
- ErrorMessage="Please enter your E-Mail address."
- ControlCssClass="required-field" />
- <com:TEmailAddressValidator
- ControlToValidate="email"
- Display="Dynamic"
- ErrorMessage="E-Mail address does not seem to be valid."
- ControlCssClass="required-field" />
- </div>
- <com:TPanel Visible=<%= $this->User->isInRole('admin') %> >
+<com:TWizard ID="CreateUserWizard"
+ UseDefaultLayout="false"
+ NavigationStyle.CssClass="wizardNav"
+ OnNextButtonClick="userWizardNextStep"
+ OnCompleteButtonClick="createNewUser"
+ ShowSideBar="false" >
+ <com:TWizardStep>
+ <h4>Sign Up for Your New Account</h4>
+ <div class="username">
+ <com:TLabel ForControl="username" Text="User Name:" />
+ <span class="required">*</span>
+ <com:TTextBox ID="username" />
+ <com:TRequiredFieldValidator
+ ControlToValidate="username"
+ Display="Dynamic"
+ ErrorMessage="Please enter your username."
+ ControlCssClass="required-field" />
+ <com:TCustomValidator
+ ControlToValidate="username"
+ Display="Dynamic"
+ OnServerValidate="checkUsername" />
+ </div>
+ <div class="password">
+ <com:TLabel ForControl="password" Text="Password:" />
+ <span class="required">*</span>
+ <com:TTextBox ID="password" TextMode="Password" />
+ <com:TRequiredFieldValidator
+ ControlToValidate="password"
+ Display="Dynamic"
+ ErrorMessage="Please enter your password (6 or more characters)."
+ ControlCssClass="required-field" />
+ <com:TRegularExpressionValidator
+ ControlToValidate="password"
+ Display="Dynamic"
+ RegularExpression="\w{6,}"
+ ErrorMessage="Please enter 6 or more characters."
+ ControlCssClass="required-field" />
+ </div>
+ <div class="password">
+ <com:TLabel ForControl="password2" Text="Confirm Password:" />
+ <span class="required">*</span>
+ <com:TTextBox ID="password2" TextMode="Password" />
+ <com:TCompareValidator
+ ControlToValidate="password"
+ ControlToCompare="password2"
+ ErrorMessage="The Password and Confirmation Password must match."
+ ControlCssClass="required-field" />
+ </div>
+ <div class="email">
+ <com:TLabel ForControl="email" Text="E-Mail Address:" />
+ <span class="required">*</span>
+ <com:TTextBox ID="email" Style="width:20em"/>
+ <com:TRequiredFieldValidator
+ ControlToValidate="email"
+ Display="Dynamic"
+ ErrorMessage="Please enter your E-Mail address."
+ ControlCssClass="required-field" />
+ <com:TEmailAddressValidator
+ ControlToValidate="email"
+ Display="Dynamic"
+ ErrorMessage="E-Mail address does not seem to be valid."
+ ControlCssClass="required-field" />
+ </div>
+ </com:TWizardStep>
+ <com:TWizardStep>
<com:TLabel ForControl="role" Text="New User Role:" />
<span class="required">*</span>
<com:TDropDownList ID="role">
<com:TListItem Text="Administrator" Value="admin,manager,consultant" />
<com:TListItem Text="Manager" Value="manager,consultant" />
<com:TListItem Text="Consultant" Value="consultant" />
- </com:TDropDownList>
- </com:TPanel>
- <div class="create">
- <com:TButton Text="Create User" OnClick="createNewUser" />
- </div>
+ </com:TDropDownList>
+ </com:TWizardStep>
+ <com:TWizardStep StepType="Complete">
+ New account has been successfully created.
+ <com:TPanel Visible=<%= !$this->User->isInRole('admin') %> CssClass="wizardNav">
+ <com:TButton Text="Continue" OnClick="wizardCompleted"/>
+ </com:TPanel>
+ </com:TWizardStep>
+</com:TWizard>
</fieldset>
</com:TContent> \ No newline at end of file
diff --git a/demos/time-tracker/protected/pages/TimeTracker/UserCreate.php b/demos/time-tracker/protected/pages/TimeTracker/UserCreate.php
index f163ecd6..ed8ea4f1 100644
--- a/demos/time-tracker/protected/pages/TimeTracker/UserCreate.php
+++ b/demos/time-tracker/protected/pages/TimeTracker/UserCreate.php
@@ -11,8 +11,10 @@
*/
/**
- * Create new user page class. Validate that the usernames are unique
- * and set the new user credentials as the current application credentials.
+ * Create new user wizard page class. Validate that the usernames are unique and
+ * set the new user credentials as the current application credentials.
+ *
+ * If logged in as admin, the user role can be change during creation.
*
* @author Wei Zhuo <weizhuo[at]gmail[dot]com>
* @version $Revision: $ $16/07/2006: $
@@ -22,6 +24,18 @@
class UserCreate extends TPage
{
/**
+ * Sets the default new user roles, default role is set in config.xml
+ */
+ public function onLoad($param)
+ {
+ if(!$this->IsPostBack)
+ {
+ $this->role->SelectedValue =
+ $this->Application->Parameters['NewUserRoles'];
+ }
+ }
+
+ /**
* Verify that the username is not taken.
* @param TControl custom validator that created the event.
* @param TServerValidateEventParameter validation parameters.
@@ -29,12 +43,27 @@ class UserCreate extends TPage
public function checkUsername($sender, $param)
{
$userDao = $this->Application->Modules['daos']->getDao('UserDao');
- $user = $userDao->getUserByName($this->username->Text);
- if(!is_null($user))
+ if($userDao->usernameExists($this->username->Text))
{
$param->IsValid = false;
$sender->ErrorMessage =
- "The user name is already taken, try '{$user->Name}01'";
+ "The user name is already taken, try '{$this->username->Text}01'";
+ }
+ }
+
+ /**
+ * Skip the role assignment step if not admin.
+ */
+ public function userWizardNextStep($sender, $param)
+ {
+ if($param->CurrentStepIndex == 0)
+ {
+ //create user with admin credentials
+ if(!$this->User->isInRole('admin'))
+ {
+ $this->createNewUser($sender, $param);
+ $param->NextStepIndex = 2;
+ }
}
}
@@ -54,31 +83,30 @@ class UserCreate extends TPage
$newUser->EmailAddress = $this->email->Text;
$newUser->Name = $this->username->Text;
$newUser->IsGuest = false;
- if($this->User->isInRole('admin'))
- $newUser->Roles = $this->role->SelectedValue;
- else
- $newUser->Roles = $this->Application->Parameters['NewUserRoles'];
+ $newUser->Roles = $this->role->SelectedValue;
//save the user
$userDao = $this->Application->Modules['daos']->getDao('UserDao');
$userDao->addNewUser($newUser, $this->password->Text);
- //update the user
+ //update the user credentials if not admin
if(!$this->User->isInRole('admin'))
{
$auth = $this->Application->getModule('auth');
$auth->updateCredential($newUser);
-
- //return to requested page
- $this->Response->redirect($auth->getReturnUrl());
}
- else
- $this->Response->reload();
- //goto default page.
- //$url = $this->Service->constructUrl($this->Service->DefaultPage);
- //$this->Response->redirect($url);
}
}
+
+ /**
+ * Continue with requested page.
+ */
+ public function wizardCompleted($sender, $param)
+ {
+ //return to requested page
+ $auth = $this->Application->getModule('auth');
+ $this->Response->redirect($auth->getReturnUrl());
+ }
}
?> \ No newline at end of file
diff --git a/demos/time-tracker/protected/pages/TimeTracker/UserList.page b/demos/time-tracker/protected/pages/TimeTracker/UserList.page
index 48b2bbc7..f0c88112 100644
--- a/demos/time-tracker/protected/pages/TimeTracker/UserList.page
+++ b/demos/time-tracker/protected/pages/TimeTracker/UserList.page
@@ -1,3 +1,33 @@
<com:TContent ID="Main">
<h1>List Users</h1>
+<fieldset>
+ <legend>User List</legend>
+
+ <com:TRepeater ID="list" EnableViewState="false">
+ <prop:HeaderTemplate>
+ <table cellpadding="2">
+ <tr class="header">
+ <th>User Name</th>
+ <th>E-Mail Address</th>
+ </tr>
+ </prop:HeaderTemplate>
+ <prop:ItemTemplate>
+ <tr class="row0">
+ <td><%#$this->DataItem->Name %></td>
+ <td><%#$this->DataItem->EmailAddress %></td>
+ </tr>
+ </prop:ItemTemplate>
+ <prop:AlternatingItemTemplate>
+ <tr class="row1">
+ <td><%#$this->DataItem->Name %></td>
+ <td><%#$this->DataItem->EmailAddress %></td>
+ </tr>
+ </prop:AlternatingItemTemplate>
+ <prop:FooterTemplate>
+ </table>
+ </prop:FooterTemplate>
+</com:TRepeater>
+<div style="padding:1em">
+ <a href="?page=TimeTracker.UserCreate">Create New User</a>
+</div>
</com:TContent> \ No newline at end of file
diff --git a/demos/time-tracker/protected/pages/TimeTracker/UserList.php b/demos/time-tracker/protected/pages/TimeTracker/UserList.php
new file mode 100644
index 00000000..175a731a
--- /dev/null
+++ b/demos/time-tracker/protected/pages/TimeTracker/UserList.php
@@ -0,0 +1,34 @@
+<?php
+/**
+ * UserList page class file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2006 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Revision: $ $18/07/2006: $
+ * @package Demos
+ */
+
+/**
+ * List all users in a repeater.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version $Revision: $ $18/07/2006: $
+ * @package Demos
+ * @since 3.1
+ */
+class UserList extends TPage
+{
+ /**
+ * Load all the users and display them in a repeater.
+ */
+ function onLoad($param)
+ {
+ $userDao = $this->Application->Modules['daos']->getDao('UserDao');
+ $this->list->DataSource = $userDao->getAllUsers();
+ $this->list->dataBind();
+ }
+}
+
+?> \ No newline at end of file