Jump to content

[My Private Notes] Encrypted Staff Private Notes


PauloV

Recommended Posts

Hello Blestars :)
 
Today we show you how to add a new option called "My Private Notes" to your "My Info" option on Blesta (We hope Blesta added this to Core :) )
 
This option encrypts all info into the database, so its a secured way to, for exemple add your passwords, links or outher info you like to your personall use :)
 
Like on WHMCS, we use a lot the "Notes" to save some info to remember later, but Blesta didnt have until today :)
 
If Blesta add this to core, on WHMCS import script, also can import the Notes from your WHMCS into your Blesta :)
 
 
Teaser:
 
private_notes.png
 
How to install (its simple)
 
Open your phpMyAdmin and on the left select your Blesta Data Base, and on the right select "SQL" and execute:
 
ALTER TABLE `staff` ADD `notes` TEXT NOT NULL AFTER `email_mobile`;
Download and upload this file (blesta_file_private_notes.zip) into your blesta instalation in app/views/admin/default/
 
Open the file languages/[your language]/admin_myinfo.php
 
 
find on line 14:
$lang['AdminMyinfo.!success.notices_updated'] = "Your notice settings were successfully updated.";
replace:
 
$lang['AdminMyinfo.!success.notices_updated'] = "Your notice settings were successfully updated.";
$lang['AdminMyinfo.!success.notes_updated'] = "Your private notes were successfully updated.";
find on line 20:
$lang['AdminMyinfo.gettabnames.text_notices'] = "Notices";
replace:
$lang['AdminMyinfo.gettabnames.text_notices'] = "Notices";
$lang['AdminMyinfo.gettabnames.text_notes'] = "Private Notes";
find on line 51:
$lang['AdminMyinfo.notices.no_subscription_results'] = "There are no subscription notices available to your staff group.";
replace:
$lang['AdminMyinfo.notices.no_subscription_results'] = "There are no subscription notices available to your staff group.";
// Private Notes
$lang['AdminMyinfo.notes.page_title'] = "My Information > Private Notes";
$lang['AdminMyinfo.notes.heading_notes'] = "My Private Notes";
$lang['AdminMyinfo.notes.field_notessubmit'] = "Update Notes";
open file app/models/staff.php
 
find on line 906:
 
public function validateNoticeActionExists($action, $staff_group_id) {
$count = $this->Record->select()->from("staff_group_notices")->
where("staff_group_id", "=", $staff_group_id)->
where("action", "=", $action)->
numResults();

return ($count > 0);
}

replace:
 
public function validateNoticeActionExists($action, $staff_group_id) {
$count = $this->Record->select()->from("staff_group_notices")->
where("staff_group_id", "=", $staff_group_id)->
where("action", "=", $action)->
numResults();

return ($count > 0);
}

/**
* Updates the given staff member private notes
*
* @param int $staff_id The ID of the staff member to update
* @param array $vars An array of staff member info including
*/
public function editNotes($staff_id, array $vars) {
// Update staff private notes
            //$vars["notes"] = systemEncrypt($vars["notes"]);
$fields = array("notes");
$this->Record->where("id", "=", $staff_id)->update("staff", $vars, $fields);
}

/**
* Fetches a staff member notes
*
* @param int $staff_id The ID of the staff member
* @param int $company_id The ID of the company to set staff settings for (optional, if null, no settings will be set)
* @return mixed An array of objects or false if no results.
* @see Staff::getByUserId()
*/
public function getNotes($staff_id, $company_id=null) {
$fields = array("staff.id", "staff.user_id", "staff.notes");

$staff = $this->Record->select($fields)->from("staff")->
where("staff.id", "=", $staff_id)->fetch();

return $staff;
}
 
open file app/controllers/admin_myinfo.php
 
find on line 147:
 
private function getGroupNotices($staff_group_id, $type) {
$this->uses(array("StaffGroups"));
// Get staff group notices
$group_notices = $this->StaffGroups->getNotices($staff_group_id);

if (!empty($group_notices)) {
// Get all client email groups
$this->uses(array("EmailGroups"));
Language::loadLang("admin_company_emails");

$email_groups = $this->EmailGroups->getAllByNoticeType($type);

// Create a list of email groups by action
$groups = array();
foreach ($email_groups as &$email_group) {
// Load plugin language
if ($email_group->plugin_dir !== null)
Language::loadLang("admin_company_emails", null, PLUGINDIR . $email_group->plugin_dir . DS . "language" . DS);

$email_group->lang = Language::_("AdminCompanyEmails.templates." . $email_group->action . "_name", true);
$email_group->lang_description = Language::_("AdminCompanyEmails.templates." . $email_group->action . "_desc", true);

// Set only those notices available to this staff group
foreach ($group_notices as $notice) {
if ($notice->action == $email_group->action) {
$groups[] = $email_group;
break;
}
}
}

return $groups;
}

return array();
}


/**
* Retrieves a list of link tabs for use in templates
*
* @return array A list of tab names
*/
private function getTabNames() {
return array(
array('name'=>Language::_("AdminMyinfo.gettabnames.text_index", true), 'uri'=>"index"),
array('name'=>Language::_("AdminMyinfo.gettabnames.text_notices", true), 'uri'=>"notices")
);
}
replace:
 
private function getGroupNotices($staff_group_id, $type) {
$this->uses(array("StaffGroups"));
// Get staff group notices
$group_notices = $this->StaffGroups->getNotices($staff_group_id);

if (!empty($group_notices)) {
// Get all client email groups
$this->uses(array("EmailGroups"));
Language::loadLang("admin_company_emails");

$email_groups = $this->EmailGroups->getAllByNoticeType($type);

// Create a list of email groups by action
$groups = array();
foreach ($email_groups as &$email_group) {
// Load plugin language
if ($email_group->plugin_dir !== null)
Language::loadLang("admin_company_emails", null, PLUGINDIR . $email_group->plugin_dir . DS . "language" . DS);

$email_group->lang = Language::_("AdminCompanyEmails.templates." . $email_group->action . "_name", true);
$email_group->lang_description = Language::_("AdminCompanyEmails.templates." . $email_group->action . "_desc", true);

// Set only those notices available to this staff group
foreach ($group_notices as $notice) {
if ($notice->action == $email_group->action) {
$groups[] = $email_group;
break;
}
}
}

return $groups;
}

return array();
}



/**
* Update this staff members private notes
*/
public function notes() {
$this->uses(array("Users"));

// Get staff and user IDs
$user_id = $this->Session->read("blesta_id");
$staff_id = $this->Session->read("blesta_staff_id");

$vars = array();

// Update the users' info
if (!empty($this->post)) {

$errors = array();

// Begin transaction
            $this->post["notes"] = $this->Users->systemEncrypt($this->post["notes"]);
$this->Staff->editNotes($staff_id, $this->post);
$staff_errors = $this->Staff->errors();

$errors = $this->Staff->errors();

if (!empty($errors)) {

$this->setMessage("error", $errors);
$vars = (object)$this->post;
}
else {
// Success, commit

$this->flashMessage("message", Language::_("AdminMyinfo.!success.notes_updated", true));
$this->redirect($this->base_uri);
}
}

// Set my info notes
if (empty($vars)) {
$staff = $this->Staff->getNotes($staff_id, $this->company_id);
            $staff->notes = $this->Users->systemDecrypt($staff->notes);
$vars = (object)(array)$staff;
}

$this->set("vars", $vars);
$this->set("link_tabs", $this->getTabNames());

return $this->renderAjaxWidgetIfAsync();
}

/**
* Retrieves a list of link tabs for use in templates
*
* @return array A list of tab names
*/
private function getTabNames() {
return array(
array('name'=>Language::_("AdminMyinfo.gettabnames.text_index", true), 'uri'=>"index"),
array('name'=>Language::_("AdminMyinfo.gettabnames.text_notices", true), 'uri'=>"notices"),
array('name'=>Language::_("AdminMyinfo.gettabnames.text_notes", true), 'uri'=>"notes")
);
}

Note: You can add the "My Private Notes" as a "Quick Link" to show on Blesta Admin Front Page, just click on "My Info" on the Top Right, then click on "Private Notes", and then click on the "Litle Star" above to add as a Quick Link

 

 

If you dont whant do all the above work (you still have to execute the SQL qwery above), and you use the latest 3.1.3 Blesta, just download this file here, and upload to your Blesta Instalation :)

 

We hope you enjoyit :)

 

Regards,

PV

 

Link to comment
Share on other sites

Could you make this a plugin? It would be better for everyone mate but I love this though.

This a very small mod, and I think Its unecessary to make as a Standalone Plugin (more tables, more files, and more coding to do just this actions), Blesta only needs to add to Core to 3.2 :P

If Tyson, Cody or Paul, tell me to make a Plugin insted, I will make a Plugin :) I think its not necessary ;)

Regards,

PV

Link to comment
Share on other sites

  • 2 months later...
  • 8 years later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...