From: Anthony Talarico Date: Fri, 15 Sep 2017 20:44:43 +0000 (-0400) Subject: setting up lockedToMember details X-Git-Tag: v1.0.0~1^2~34 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/index.cgi?a=commitdiff_plain;h=e10d88303d3658e5f6f09f6a562cbb3f55e10947;p=WP-Plugins%2Fglm-member-db-jobs.git setting up lockedToMember details adding the necessary data and files to make sure only members can edit their own job postings --- diff --git a/config/plugin.ini b/config/plugin.ini index 52970d4..4bf5d8f 100644 --- a/config/plugin.ini +++ b/config/plugin.ini @@ -9,4 +9,4 @@ ; Entry Status Types ; job_expiration[30] = '30 Days' -job_expiration[60] = '60 days' \ No newline at end of file +job_expiration[60] = '60 Days' \ No newline at end of file diff --git a/css/front.css b/css/front.css index e69de29..8aa5d3f 100644 --- a/css/front.css +++ b/css/front.css @@ -0,0 +1,6 @@ +.no-padding{ + padding: 0; +} +.front-job-list-row{ + margin-bottom: 20px; +} \ No newline at end of file diff --git a/models/admin/jobs/index.php b/models/admin/jobs/index.php index f934c51..beaab49 100644 --- a/models/admin/jobs/index.php +++ b/models/admin/jobs/index.php @@ -88,22 +88,84 @@ class GlmMembersAdmin_jobs_index extends GlmDataJobs public function modelAction($actionData = false) { + $members = new GlmDataMembers($this->wpdb, $this->config); + $member_list = $members->getList(); + $job_titles = new GlmDataJobTitles($this->wpdb,$this->config); $job_titles = $job_titles->getList(); - if( ! wp_script_is( 'jquery-ui', 'enqueued' ) ){ - wp_enqueue_script('jquery-ui-datepicker', false, array('jquery'), false, true); - wp_enqueue_style('jquery-style', '//ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css'); + $success_message = ""; + $haveJob = false; + $option = false; + $job = false; + $job_data = false; + $jobUpdated = false; + $jobUpdateError = false; + $jobAdded = false; + $jobAddError = false; + $view_file = 'index'; + $lockedToMember = false; + $isModerated = false; + $memberID = false; + $haveMember = false; + $where = ''; + + // Check if there's a logged in user who is locked to their own entity + $lockedToMember = apply_filters('glm_members_locked_to_member_id', false); + if ($lockedToMember) { + + $isModerated = apply_filters('glm_user_is_moderated', $lockedToMember); + $memberID = $lockedToMember; + + $this->fields['admin_name']['required'] = true; + $this->fields['admin_email']['required'] = true; + $this->fields['admin_phone']['required'] = true; + + // Check for Member Menu Use + } elseif (defined('GLM_JOB_MEMBER_MENU')) { + + // Try to get member ID + $memberID = (isset($_REQUEST['member']) ? $_REQUEST['member'] : 0); + + // If there's no valid member ID, we can't continue + if ($memberID == 0) { + return array( + 'status' => false, + 'menuItemRedirect' => 'error', + 'modelRedirect' => 'index', + 'view' => 'admin/error/index.html', + 'data' => array( + 'reason' => 'No member ID was provided.' + ) + ); + } + } + + // If not a valid member ID + if ($memberID > 0) { + + // Get base member information + require_once GLM_MEMBERS_PLUGIN_CLASS_PATH.'/data/dataMembers.php'; + + $memberData = $members->getEntry($memberID); + $where .= "member = $memberID"; + if (!$memberData) { + return array( + 'status' => false, + 'menuItemRedirect' => 'error', + 'modelRedirect' => 'index', + 'view' => 'admin/error/index.html', + 'data' => array( + 'reason' => 'No member data found for provided member ID.' + ) + ); + } else{ + $haveMember = true; + $memberName = $memberData['name']; + } + } - $success_message = ""; - $haveJob = false; - $option = false; - $job = false; - $jobUpdated = false; - $jobUpdateError = false; - $jobAdded = false; - $jobAddError = false; - $view_file = 'index'; + if (isset($_REQUEST['option']) && trim($_REQUEST['option']) != '') { $option = $_REQUEST['option']; } @@ -118,10 +180,9 @@ class GlmMembersAdmin_jobs_index extends GlmDataJobs if ($this->job_id <= 0) { $this->job_id = false; } - } - - $job_data = $this->getList(); + + $job_data = $this->getList($where); // echo '
', print_r($this->getList()), '
'; // echo '
', print_r($_REQUEST), '
'; @@ -162,7 +223,7 @@ class GlmMembersAdmin_jobs_index extends GlmDataJobs case 'edit': $job = $this->editEntry($this->job_id); - + // If we have a good Job if ($job['status']) { $haveJob = true; @@ -187,7 +248,7 @@ class GlmMembersAdmin_jobs_index extends GlmDataJobs $haveJob = true; $view_file = 'edit'; - + break; case 'delete': @@ -202,7 +263,7 @@ class GlmMembersAdmin_jobs_index extends GlmDataJobs $job_data = $this->getList(); break; default: - $job_data = $this->getList(); + $job_data = $this->getList($where); $view_file = 'index'; break; } @@ -210,6 +271,10 @@ class GlmMembersAdmin_jobs_index extends GlmDataJobs // Compile template data $templateData = array( 'jobData' => $job_data, + 'memberList' => $member_list, + 'lockedToMember' => $lockedToMember, + 'haveMember' => $haveMember, + 'memberID' => $memberID, 'jobTitles' => $job_titles, 'jobID' => $this->job_id, 'haveJob' => $haveJob, diff --git a/models/front/jobs/detail.php b/models/front/jobs/detail.php new file mode 100644 index 0000000..18e1276 --- /dev/null +++ b/models/front/jobs/detail.php @@ -0,0 +1,148 @@ + + * @license http://www.gaslightmedia.com Gaslightmedia + * @release index.php,v 1.0 2014/10/31 19:31:47 cscott Exp $ + * @link http://dev.gaslightmedia.com/ + */ + +// Load Contacts data abstract +require_once GLM_MEMBERS_JOBS_PLUGIN_CLASS_PATH.'/data/dataJobs.php'; +require_once GLM_MEMBERS_JOBS_PLUGIN_CLASS_PATH.'/data/dataJobTitles.php'; + +class GlmMembersFront_jobs_detail extends GlmDatajobs +{ + + /** + * WordPress Database Object + * + * @var $wpdb + * @access public + */ + public $wpdb; + /** + * Plugin Configuration Data + * + * @var $config + * @access public + */ + public $config; + /** + * Contact Info + * + * @var $contactInfo + * @access public + */ + public $contactInfo = false; + /** + * Member ID + * + * @var $memberID + * @access public + */ + public $memberID = false; + /** + * Contact ID + * + * @var $contactID + * @access public + */ + public $contactID = false; + public $job_id; + + /* + * Constructor + * + * This contructor performs the work for this model. This model returns + * an array containing the following. + * + * 'status' + * + * True if successfull and false if there was a fatal failure. + * + * 'view' + * + * A suggested view name that the contoller should use instead of the + * default view for this model or false to indicate that the default view + * should be used. + * + * 'data' + * + * Data that the model is returning for use in merging with the view to + * produce output. + * + * @wpdb object WordPress database object + * + * @return array Array containing status, suggested view, and any data + */ + public function __construct ($wpdb, $config) + { + + // Save WordPress Database object + $this->wpdb = $wpdb; + + // Save plugin configuration object + $this->config = $config; + + /* + * Run constructor for the Contacts data class + * + * Note, the third parameter is a flag that indicates to the Contacts + * data class that it should flag a group of fields as 'view_only'. + */ + parent::__construct(false, false, true); + + + } + + public function modelAction($actionData = false) + { + $job_titles = new GlmDataJobTitles($this->wpdb,$this->config); + $job_titles = $job_titles->getList(); + + $success_message = ""; + $option = false; + if (isset($_REQUEST['option']) && trim($_REQUEST['option']) != '') { + $option = $_REQUEST['option']; + } + // get the Job id for use in the edit, add and delete options + // Get obit ID if supplied + if (isset($_REQUEST['job'])) { + + // Make sure it's numeric + $this->job_id= ($_REQUEST['job'] - 0); + + if ($this->job_id <= 0) { + $this->job_id = false; + } + } + $where = "id = $this->job_id"; + + $job = $this->getList($where); + foreach($job as $j){ + $job = $j; + } + // Compile template data + $templateData = array( + 'jobData' => $job, + 'jobTitles' => $job_titles, + 'siteBaseUrl' => GLM_MEMBERS_JOBS_SITE_BASE_URL, + 'currentUrl' => GLM_MEMBERS_JOBS_PLUGIN_CURRENT_URL, + ); + + // Return status, any suggested view, and any data to controller + return array( + 'status' => true, + 'modelRedirect' => false, + 'view' => 'front/jobs/detail.html', + 'data' => $templateData + ); + } +} diff --git a/models/front/jobs/list.php b/models/front/jobs/list.php index 7452ac1..ef61095 100644 --- a/models/front/jobs/list.php +++ b/models/front/jobs/list.php @@ -15,6 +15,7 @@ // Load Contacts data abstract require_once GLM_MEMBERS_JOBS_PLUGIN_CLASS_PATH.'/data/dataJobs.php'; +require_once GLM_MEMBERS_JOBS_PLUGIN_CLASS_PATH.'/data/dataJobTitles.php'; class GlmMembersFront_jobs_list extends GlmDatajobs { @@ -103,42 +104,32 @@ class GlmMembersFront_jobs_list extends GlmDatajobs public function modelAction($actionData = false) { + $job_titles = new GlmDataJobTitles($this->wpdb,$this->config); + $job_titles = $job_titles->getList(); + $success_message = ""; $option = false; if (isset($_REQUEST['option']) && trim($_REQUEST['option']) != '') { $option = $_REQUEST['option']; } - // separate the main Job info and the individual details - $job_data = $this->getList(); - foreach($job_data as $id=>$record){ - foreach($record as $key=>$value){ - if(strpos($key, "Job") !== false){ - $jobs['trail_Job'][$id]['job_info'][$key] = $value; - } else { - $jobs['trail_Job'][$id]['trail_info'][$key] = $value; - } - } + if (isset($_REQUEST['job_titles']) && $_REQUEST['job_titles'] !== '') { + // Make sure it's numeric + $job_title_id = ($_REQUEST['job_titles'] - 0); + $where = "title = $job_title_id"; + $job_data = $this->getList($where); + } else { + $job_data = $this->getList(); } -// echo '
', print_r($jobs), '
'; - $view_file = 'list'; - switch ($option) { - - case "edit": - $view_file = 'edit'; - break; - - default: - - break; - } - + $view_file = 'list'; - // Compile template data $templateData = array( - 'jobData' => $jobs + 'jobData' => $job_data, + 'jobTitles' => $job_titles, + 'siteBaseUrl' => GLM_MEMBERS_JOBS_SITE_BASE_URL, + 'currentUrl' => GLM_MEMBERS_JOBS_PLUGIN_CURRENT_URL, ); // Return status, any suggested view, and any data to controller diff --git a/setup/adminMenus.php b/setup/adminMenus.php index fb5cee9..d15d483 100644 --- a/setup/adminMenus.php +++ b/setup/adminMenus.php @@ -49,11 +49,22 @@ * is named the same as the "glm_action" parameter. * */ -add_submenu_page( - 'glm-members-admin-menu-members', - 'Job Postings', - 'Job Postings', - 'edit_posts', - 'glm-members-admin-menu-jobs-index', - function(){$this->controller('jobs');} -); + if (isset($this->config['loggedInUser']) && isset($this->config['loggedInUser']['contactUser']) && $this->config['loggedInUser']['contactUser']) { + add_submenu_page( + $mainMenuSlug, + 'Job Postings', + 'Job Postings', + 'glm_members_edit_my_entity', + 'glm-members-admin-menu-jobs-index', + function(){$this->controller('jobs');} + ); +} else { + add_submenu_page( + 'glm-members-admin-menu-members', + 'Job Postings', + 'Job Postings', + 'edit_posts', + 'glm-members-admin-menu-jobs-index', + function(){$this->controller('jobs');} + ); +} diff --git a/setup/permissions.php b/setup/permissions.php index 68554ec..a52a19b 100644 --- a/setup/permissions.php +++ b/setup/permissions.php @@ -51,3 +51,16 @@ * * $permit is a boolean set before this function call for passing on permissions. */ +// Logged in all members manager user may edit an event for all members +add_filter('glm_members_permit_admin_members_job', + function($permit) { + return glmMembersUserCan('glm_members_edit_any_member', $permit); + } +); + +// Logged in member user may edit an event only for their own entity +add_filter('glm_members_permit_admin_member_job', + function($permit) { + return glmMembersUserCan('glm_members_edit_my_member', $permit); + } +); diff --git a/setup/shortcodes.php b/setup/shortcodes.php index 706f5a7..ee6651f 100644 --- a/setup/shortcodes.php +++ b/setup/shortcodes.php @@ -88,7 +88,7 @@ */ $glmMembersjobsShortcodes = array( - 'glm-jobs' => array( + 'glm-members-jobs' => array( 'plugin' => GLM_MEMBERS_JOBS_PLUGIN_SLUG, 'menu' => 'jobs', 'action' => 'list', @@ -98,6 +98,15 @@ $glmMembersjobsShortcodes = array( 'member_only' => true ) ), + 'glm-members-job-detail' => array( + 'plugin' => GLM_MEMBERS_JOBS_PLUGIN_SLUG, + 'menu' => 'jobs', + 'action' => 'detail', + 'table' => false, + 'attributes' => array( + 'id' => false, + ) + ), ); $glmMembersjobsShortcodesDescription = ''; diff --git a/setup/validActions.php b/setup/validActions.php index 9c46898..8e6c5b2 100644 --- a/setup/validActions.php +++ b/setup/validActions.php @@ -69,7 +69,8 @@ $glmMembersjobsAddOnValidActions = array( ), 'frontActions' => array( 'jobs' => array( - 'list' => GLM_MEMBERS_JOBS_PLUGIN_SLUG + 'list' => GLM_MEMBERS_JOBS_PLUGIN_SLUG, + 'detail' => GLM_MEMBERS_JOBS_PLUGIN_SLUG, ), ) ); diff --git a/views/admin/jobs/edit.html b/views/admin/jobs/edit.html index b5c1694..04db4f0 100644 --- a/views/admin/jobs/edit.html +++ b/views/admin/jobs/edit.html @@ -22,7 +22,6 @@ {/if}
- {if $haveJob} @@ -56,7 +55,8 @@ - + + {if !$lockedToMember}
Member @@ -64,18 +64,19 @@
+ {/if}
diff --git a/views/admin/jobs/index.html b/views/admin/jobs/index.html index e8652fb..036f542 100644 --- a/views/admin/jobs/index.html +++ b/views/admin/jobs/index.html @@ -1,5 +1,11 @@ {include file='admin/header.html'} - +{if $haveMember} + +{if !$lockedToMember} + +{/if} + +{/if} {if $jobData}
New Job Posting diff --git a/views/front/jobs/detail.html b/views/front/jobs/detail.html index c627c24..06e3200 100644 --- a/views/front/jobs/detail.html +++ b/views/front/jobs/detail.html @@ -1,16 +1,26 @@ - - - - - TODO supply a title - - - - -
TODO write content
- - + +
+
{$jobData.title}
+
{$jobData.job_location}
+
{$jobData.position_available}
+
{$jobData.salary}
+
{$jobData.duration}
+
{$jobData.company}
+
{$jobData.facility_operation}
+
{$jobData.descr}
+
{$jobData.requirements}
+
{$jobData.benefits}
+
{$jobData.email_location}
+
{$jobData.email_location}
+
{$jobData.contactphone}
+
\ No newline at end of file diff --git a/views/front/jobs/list.html b/views/front/jobs/list.html index dd13ac3..12eb564 100644 --- a/views/front/jobs/list.html +++ b/views/front/jobs/list.html @@ -1,12 +1,40 @@ -{foreach $jobData as $key=>$value} - {foreach $value as $id=>$job} -
-
- -
-
- jobs + +{if $jobData} + {foreach $jobData as $key=>$value} +
+
+
+
+ {$value.title} +
+
+ Location: {$value.job_location} +
+
+ Company: {$value.company} +
+
+ {$value.post_date.timestamp|date_format:"%Y-%m-%d"} +
+ Full Job Description +
{/foreach} -{/foreach} \ No newline at end of file +{else} +
+
+ No Job Listings +
+
+{/if} \ No newline at end of file