Jump to content

Xtremer360

Members
  • Posts

    1,444
  • Joined

  • Last visited

Everything posted by Xtremer360

  1. What's supposed to happen is after the user logs in it has the default character id and the role id of the user that is held in the userData array. It runs the library function getRosterList. Inside that function it checks to see if the user has a role id of 4(admin) or 5(superadmin) and if they are then what I want it to do is get ALL the roster members which would include their default character and have it as the selected option. If they are not one of those two roles then I just want it to get the roster members that they control and have the preselected option as the default character id. And if they only have one character then it displays a h1 tag instead of the dropdown. Here's also my view file. <?php echo '<pre>'; print_r($userRoster); echo '</pre>'; if (count($userRoster) == 1) { echo '<h1>'.$userRoster->rosterName.'</h1>'; } else { $options = array ( $userRoster['id'] => $userRoster->rosterName ); echo form_dropdown('userCharacters', $options, '', 'id="userCharacter"'); } ?>
  2. If user role is a user or editor then either display their default character or if more than one character then display dropdown of all handled characters. If user role is an administrator or webmaster then display their default character or ALL characters. Displays Active (status-1), Inactive(status-2), Injured(status-3, Alumni(status-4) in separate option groups controller: $this->data['userRoster'] = $this->kowauth->getRosterList($this->data['userData']->usersRolesID); library: /** * Get roster list * * @param integer * @return object/NULL */ function getRosterList($usersRolesID) { if (($usersRolesID == 4) || ($usersRolesID == 5)) { return $this->ci->users->getAllRoster(); } else { return $this->ci->users->getRosterByUserID($this->ci->session->userdata('usersID')); } } Model: /** * Get roster list * * @return object/NULL */ function getAllRoster() { $this->db->select('rosterName'); $this->db->from('rosterList'); $this->db->order_by('rosterName'); $query = $this->db->get(); if ($query->num_rows() > 0) { return $query->result(); } return null; } /** * Get list of roster by user ID * * @return object/NULL */ function getRosterByUserID($usersID) { $this->db->select('rosterName'); $this->db->from('rosterList'); $this->db->where('userID', $usersID); $this->db->order_by('rosterName'); $query = $this->db->get(); if ($query->num_rows() > 0) { return $query->result(); } return null; }
  3. Now I have to figure out how to work with that in my library and model for my CodeIgniter project.
  4. I'm not sure about this but curious on the purpose of it.
  5. I'm trying to figure out how I can reduce as much functionality as possible and still keep it doing what it needs to do. What I mean by functionality is the number of queries being performed or any of the other code for that matter. I do show at the bottom of my post what I have so far, however that doesn't cover all the queries. <?php if ($access_level_id == 2 || $access_level_id == 3) { $query = "SELECT characters.id FROM characters"; $result = mysqli_query ($dbc,$query); $total_num_characters = mysqli_num_rows($result); $query = "SELECT user_characters.id FROM user_characters INNER JOIN user_accounts ON user_accounts.id = user_characters.user_id"; } else { $query = "SELECT user_characters.id FROM user_characters INNER JOIN user_accounts ON user_accounts.id = user_characters.user_id WHERE user_accounts.id = '".$user_id."'"; } $result = mysqli_query($dbc,$query); echo $num_available_characters = mysqli_num_rows($result); if (($num_available_characters > "1") || (($access_level_id == 2 || $access_level_id == 3) && (isset($total_num_characters)) && ($total_num_characters > "0"))) { ?> <form method="POST" id="change_default_character"> <select class="dropdown" name="new_default_character_id" id="new_default_character_id" title="Select Character"> <?php if ($default_character_id > "0") { print "<option value=".$default_character_id.">".$default_character_name; } else { print "<option value=0>- Select -"; } if ($access_level_id == 2 || $access_level_id == 3) { $query = "SELECT characters.id, characters.character_name FROM characters WHERE characters.id <> '".$default_character_id."' AND characters.status_id = '1' ORDER BY characters.character_name"; } else { $query = "SELECT characters.id, characters.character_name FROM characters INNER JOIN user_characters ON characters.id = user_characters.character_id INNER JOIN user_accounts ON user_accounts.id = user_characters.user_id WHERE user_accounts.id = '".$user_id."' AND user_characters.character_id <> '".$default_character_id."' AND characters.status_id = '1' ORDER BY characters.character_name"; } $result = mysqli_query ($dbc,$query); $num_rows = mysqli_num_rows ($result); if ($num_rows > 0) { if ($access_level_id == 2 || $access_level_id == 3) { print "<optgroup label=\"** Active Characters **\">"; } while ( $row = mysqli_fetch_array ( $result, MYSQL_ASSOC ) ) { print "<option value=\"".$row['id']."\">".$row['character_name']."</option>\r"; } } if ($access_level_id == 2 || $access_level_id == 3) { $query = "SELECT characters.id, characters.character_name FROM characters WHERE characters.id <> '".$default_character_id."' AND characters.status_id = '2' ORDER BY characters.character_name"; } else { $query = "SELECT characters.id, characters.character_name FROM characters LEFT JOIN user_characters ON characters.id = user_characters.character_id LEFT JOIN user_accounts ON user_accounts.id = user_characters.user_id WHERE user_accounts.id = '".$user_id."' AND user_characters.character_id <> '".$default_character_id."' AND characters.status_id = '2' ORDER BY characters.character_name"; } $result = mysqli_query ($dbc,$query); $num_nows = mysqli_num_rows($result); if ($num_rows > "0") { print "<optgroup label=\"** Inactive Characters **\">"; while ( $row = mysqli_fetch_array ( $result, MYSQL_ASSOC ) ) { print "<option value=\"".$row['id']."\">".$row['character_name']."</option>\r"; } } ?> </select> </form> <?php } else { print "<h1>".$default_character_name."</h1>\n"; } ?> <?php /** * Get roster list * * @return object/NULL */ function getRosterList() { $this->db->from('rosterList'); $query = $this->db->get(); if ($query->num_rows() > 0) { return $query->result(); } return null; } /** * Get list of roster by user ID * * @return object/NULL */ function getRosterByUserID() { $this->db->from('rosterList'); $this->db->where('userID', $userID); $query = $this->db->get(); if ($query->num_rows() > 0) { return $query->result(); } return null; } ?>
  6. I did some testing and am now to the point where what if bcc doesn't contain anything.
  7. I reworked the function just a little and came up with this but want to know how to handle the fact of if the inserts are ran successfully or not with returning TRUE or FALSE. function sendMessage($recipients, $bcc, $subject, $message, $sender) { $data = array( 'subject' => $subject, 'senderID' => $sender, 'message' => $message ); $this->db->insert('usersPersonalMessages', $data); $insertID = $this->db->insert_id(); foreach ($recipients as $recipientID) { $recipientData = array ( 'userID' => $recipientID, 'usersPersonalMessagesID' => $insertID ); $this->db->insert('usersPersonalMessagesRecipients', $recipientData); } if ($bcc) { foreach ($bcc AS $bccID) { $bccData = array ( 'userID' => $bccID, 'usersPersonalMessagesID' => $insertID ); $this->db->insert('usersPersonalMessagesRecipients', $bccData); } } return TRUE; }
  8. It says <b>Fatal error</b>: Cannot use [] for reading in <b>/home/xtremer/public_html/kowmanager/application/models/kow_auth/pmmodel.php</b> on line <b>141</b><br /> but there's not even 141 lines in the file.
  9. The controller is apparently fixed however now the model is still needing fixed.
  10. okay well recipient[] is not an array but recipient is
  11. I did right above the sendMessage function in the controller it says bool(false)
  12. I'm assuming on the controller?
  13. I tried that but for some reason nothing printed
  14. So I need to do print_r($this->input->post[recipient[])
  15. Yeah for some reason its not an array but I don't know why its not. Here's my posting parameters from the form: bcc[] 10000 bcc[] 10001 message dafdafdasf recipient[] 10000 recipient[] 10001 sender 10000 subject Testiung submit Submit Message And here's what's inside my controller: // Function used for login form validation function pmsubmit() { $outputArray = array('error' => 'yes', 'message' => 'unproccessed'); // Sets validation rules for the login form $this->form_validation->set_rules('recipient[]', 'Recipient', 'required|is_natural_no_zero'); $this->form_validation->set_rules('bcc[]', 'Bcc', 'is_natural_no_zero'); $this->form_validation->set_rules('subject', 'Subject', 'trim|required|xss_clean'); $this->form_validation->set_rules('message', 'Message', 'trim|required|xss_clean'); $this->form_validation->set_rules('sender', 'Sender', 'required|integer'); // Checks to see if login form was submitted properly if (!$this->form_validation->run()) { $outputArray['message'] = 'There was a problem submitting the form! Please refresh the window and try again!'; } else { if ($this->users->usersExists($this->input->post('recipient[]'))) { $outputArray['message'] = 'One or more of the recipients could not be found in the database!'; } if ($this->input->post('bcc[]')) { if ($this->users->usersExists($this->input->post('bcc[]'))) { $outputArray['message'] = 'One or more of the bcc users could not be found in the database!'; } } $sender = $this->users->getUserByUserID($this->input->post('sender')); if ($sender == NULL) { $outputArray['message'] = 'You were for some reason not found in the database!'; } if ($this->pmmodel->sendMessage($this->input->post('recipient[]'), $this->input->post('bcc[]'), $this->input->post('subject'), $this->input->post('message'), $this->input->post('sender'))) { $outputArray = array('success' => 'Yes', 'message' => 'Message was sent successfully!'); } else { $outputArray['message'] = 'Message could not get sent!'; } } echo json_encode($outputArray); }
  16. 120: foreach ($recipients AS $recipient) 137: $this->db->insert('usersPersonalMessagesRecipients', $recipientData[]);
  17. <p>Severity: Warning</p> <p>Message: Invalid argument supplied for foreach()</p> <p>Filename: kow_auth/pmmodel.php</p> <p>Line Number: 120</p> </div><br /> <b>Fatal error</b>: Cannot use [] for reading in <b>/home/xtremer/public_html/kowmanager/application/models/kow_auth/pmmodel.php</b> on line <b>137</b><br /> function sendMessage($recipients, $bcc, $subject, $message, $sender) { $data = array( 'subject' => $subject, 'senderID' => $sender, 'message' => $message ); $this->db->insert('usersPersonalMessages', $data); $insertID = $this->db->insert_id(); foreach ($recipients AS $recipient) { $recipientData = array( 'usersPersonalMessagesID' => $insertID, 'userID' => $recipient ); } if ($bcc) { foreach ($bcc AS $userID) { $recipientData['userID'][] = $userID; $recipientData['type'][] = 2; } } $this->db->insert('usersPersonalMessagesRecipients', $recipientData[]); }
  18. However I did want to say that I'm getting the same to issues still.
  19. Awesome but what do you mean by that last part.
  20. I am getting a invalid argument for this line foreach ($recipients AS $recipient) AND me having to use the set method but I don't think I'd have to for this line $this->db->insert('usersPersonalMessagesRecipients', $recipientData);
  21. Is my logic even right you think?
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.