ranwilli
Member
Heres a script I "ccoked up" from snippets I found here and other places.
Client has three types of employees:emt medic and staff.
He has memo's (Joomla Articles) that he needs to assign to them to read.
To provide a module of "incomplete" assignments to a user upon Login, We made two lists: assign a memo, and record of memo assignments.
This script is to fill in the records with a row for each user containing fields:
assignment id (from the other list), user_id (of the "assigned user"), user_group_id, assigned_article_id,completed (yes or no).
Here's the code, Where did I go wrong?
Thanks.
Client has three types of employees:emt medic and staff.
He has memo's (Joomla Articles) that he needs to assign to them to read.
To provide a module of "incomplete" assignments to a user upon Login, We made two lists: assign a memo, and record of memo assignments.
This script is to fill in the records with a row for each user containing fields:
assignment id (from the other list), user_id (of the "assigned user"), user_group_id, assigned_article_id,completed (yes or no).
Here's the code, Where did I go wrong?
Code:
<?php
/**
* @package Joomla
* @subpackage Fabrik
* @copyright Copyright (C) 2005 Rob Clayburn. All rights reserved.
* Modified by Randy Williams - Harper Vance Web Services.
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
*/
// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die();
$memo = {memo_assignments___assigned_article_id} ;//memo number
$emt = {memo_assignments___emt_assigned};//emt yes or no
$medic = {memo_assignments___medic_assigned};//medic yes or no
$staff = {memo_assignments___staff_assigned};//staff yes or no
$assigner = {memo_assignments___user};//Super User that made the assignment
$emtvalue = "9";
$medicvalue = "10";
$staffvalue = "11";
//test for assignment to emt's
if ($emt != 0) {
// Get a db connection.
$db = JFactory::getDbo();
// Create a new query object.
$query = $db->getQuery(true);
$query
->select(array('m.user_id'))
->from('X__user_usergroup_map AS m')
->join('LEFT', '#_users AS u ON (m.user_id=u.id)')
->where('X__user_usergroup_map.group_id = $emtvalue')
->order('X__user_usergroup_map.group_id ASC');
$db->setQuery($query);
$r = $db->loadObjectList();
// Create a new query object.
$query = $db->getQuery(true);
//build query
foreach($rows as $r) {
$query = "INSERT INTO assignment_records (date_time, assigment_id, user_id, user_group_id, assigned_article_id, completed) VALUES ( '$now', '$memo', '$r->id', '$emtvalue', '0')";}
$db->setQuery($query);
$db->query();
}
//test for assignment to medics
if ($medic != 0) {
// Get a db connection.
$db = JFactory::getDbo();
// Create a new query object.
$query = $db->getQuery(true);
$query
->select(array('m.user_id'))
->from('X__user_usergroup_map AS m')
->join('LEFT', '#_users AS u ON (m.user_id=u.id)')
->where('X__user_usergroup_map.group_id = $medicvalue')
->order('X__user_usergroup_map.group_id ASC');
$db->setQuery($query);
$r = $db->loadObjectList();
// Create a new query object.
$query = $db->getQuery(true);
//build query
foreach($rows as $r) {
$query = "INSERT INTO assignment_records (date_time, assigment_id, user_id, user_group_id, assigned_article_id, completed) VALUES ( '$now', '$memo', '$r->id', '$medicvalue', '0')";}
$db->setQuery($query);
$db->query();
}
//test for assignment to staff
if ($staff != 0) {
// Get a db connection.
$db = JFactory::getDbo();
// Create a new query object.
$query = $db->getQuery(true);
$query
->select(array('m.user_id'))
->from('X__user_usergroup_map AS m')
->join('LEFT', '#_users AS u ON (m.user_id=u.id)')
->where('X__user_usergroup_map.group_id = $staffvalue')
->order('X__user_usergroup_map.group_id ASC');
$db->setQuery($query);
$r = $db->loadObjectList();
// Create a new query object.
$query = $db->getQuery(true);
//build query
foreach($rows as $r) {
$query = "INSERT INTO assignment_records (date_time, assigment_id, user_id, user_group_id, assigned_article_id, completed) VALUES ( '$now', '$memo', '$r->id', '$staffvalue', '0')";}
$db->setQuery($query);
$db->query();
}
?>