if ($options) {
$select = ($selected) ? 'selected' : '';
$list = '';
foreach ($options as $option) {
$list .= "";
}
return $list;
}
}
/**
* check if the current user has permission to delete selected user
* @param obj $user user model
* @return string
*/
function runtimeTeamPermissionDelete($user = '') {
//no permissions generally
if (!auth()->user()->is_admin && auth()->user()->role->role_team != 3) {
return false;
}
//cannot delete primary admin
if ($user->primary_admin == 'yes') {
return false;
}
//cannot delete yourself
if ($user->id == auth()->user()->id) {
return false;
}
//cannot delete admin user if you are not an admin user
if ($user->is_admin && !auth()->user()->is_admin) {
return false;
}
return true;
}
/**
* check if the current user has permission to edit selected user
* @param obj $user user model
* @return bool
*/
function runtimeTeamPermissionEdit($user = '') {
//no permissions generally
if (!auth()->user()->is_admin && auth()->user()->role->role_team != 3) {
return false;
}
//cannot edit primary admin
if ($user->primary_admin == 'yes') {
return false;
}
//cannot edit admin user if you are not an admin user
if ($user->is_admin && !auth()->user()->is_admin) {
return false;
}
return true;
}
/**
* permission to add an administrator level user
* @param int $role role id
* @return bool
*/
function runtimeTeamCreateAdminPermissions($role = '') {
//not an admin role
if ($role > 1) {
return true;
}
//no permissions generally
if (auth()->user()->is_admin) {
return true;
}
return false;
}
/**
* check if any item in the list is true (i.e. visible) so as to make whole menu visible
* @param array $list bool states of menu items in the group
* @return bool
*/
function runtimeGroupMenuVibility($list = []) {
foreach ($list as $value) {
if ($value === true) {
return true;
}
}
return false;
}
/**
* temporarily add full path for ajax repsonse with image paths. relative paths
* are not alwyas working for images
* @param string $test text body (usually a comment or tinymce text area)
* @return bool
*/
function runtimeTempImagePathFix($text = '') {
return preg_replace('%src="storage/files%', 'src="/storage/files', $text);
}
/**
* @param bool $required
* @return string
*/
function runtimeWebformRequiredBold($required) {
return ($required === true) ? 'required' : '';
}
/**
* @param bool $required
* @return string
*/
function runtimeWebformRequiredAsterix($required) {
return ($required === true) ? '*' : '';
}
/**
* Visibility of various form fiels in the add-edit modal for articles
* @param string value normally coming from the database
* @return string css hidden|null
*/
function runtimeVisibilityKBArticle($field = '', $category_type = '') {
//we are creating in a type of category that matches this content type (so show the editor or the embed box, respectively)
if ($field != '') {
if ($field == $category_type) {
return;
}
}
//hide this element
return 'hidden';
}
/**
* for correcting symbols that are not showing, such as euro
* @param string $number current users setting
* @param string $spanid if we want to wrap the figure in a span
* @return string css setting
*/
function runtimeMoneyFormatPDF($number = '', $span_id = "") {
$number = runtimeNumberFormat($number);
//are we wrapping in a span
if ($span_id != '') {
$number = '' . $number . '';
}
return runtimePDFCharacters(config('system.currency_symbol_left')) . $number . runtimePDFCharacters(config('system.currency_symbol_right'));
}
/** -------------------------------------------------------------------------
* A fix for some currency symbolsnow showing correctly in the PDF
* To add new currencies, add a pair of the currency and its corresponding
* html code.
*
* You then use this function in the PDF templatem, in every place that a
* currency symbol is displayed
*
* @param string $value the real currency symply (e.g. $)
* @return string corresponding html code for the currency symbol
* -------------------------------------------------------------------------*/
function runtimePDFCharacters($value = '') {
//currency symbols (you can add more here)
$search = array('€', '?');
//corresponding HTML codes for the currency symbols (in the correct order as above)
$replace = array('€', '₫');
//return the html code for the currency symbol
return str_replace($search, $replace, $value);
}
/** -------------------------------------------------------------------------
* Delete all flash messages (success & error). This is needed when sometimes
* we are using ajax and keep getting a previous flash message.
*
* Just add this to any method in the controllers
*
* @return null
* -------------------------------------------------------------------------*/
function runtimeClearFlashMessages() {
request()->session()->forget('flash-error-message');
request()->session()->forget('error-notification-long');
request()->session()->forget('success-notification');
request()->session()->forget('success-notification-long');
}
/**
* get a cover image for projects for task covers
* @return string
*/
function getCoverImage($directory = '', $filename = '', $type = 'background') {
//check if cover exists
if (Storage::exists("/files/$directory/$filename") && $filename != '' && $directory != '') {
if ($type == 'background') {
return "style=\"background-image: url(storage/files/$directory/$filename)\"";
}
if ($type == 'image') {
return url("storage/files/$directory/$filename");
}
}
//default placeholder cover
return "style=\"background-image: url('public/images/placeholder.jpg')\"";
}
/**
* get a cover image for projects for task covers
* @return string
*/
function checkCoverImage($directory = '', $filename = '') {
//check if cover exists
if (Storage::exists("/files/$directory/$filename") && $filename != '' && $directory != '') {
return true;
}
return false;
}
/**
* return a singular or translated string
* @param string $interval e.g. day|week|month|year
* @param int $interval_count e.g. 2 (for 2 weeks)
* @return string e.g. Month | 2 Months
*/
function runtimeIntervalPlural($interval_count = 1, $interval = '') {
//validate
if ($interval == '') {
return '---';
}
//translate intervals
$lang = [
'day' => ucwords(__('lang.day')),
'week' => ucwords(__('lang.week')),
'month' => ucwords(__('lang.month')),
'year' => ucwords(__('lang.year')),
];
$lang_plural = [
'day' => ucwords(__('lang.days')),
'week' => ucwords(__('lang.weeks')),
'month' => ucwords(__('lang.months')),
'year' => ucwords(__('lang.years')),
];
//validate
if (!array_key_exists($interval, $lang) || !is_numeric($interval_count)) {
return;
}
if ($interval_count == 1) {
return $interval_count . ' ' . $lang[$interval];
} else {
return $interval_count . ' ' . $lang_plural[$interval];
}
}
/**
* show or hide task recurring icom
* @param string $var current users setting
* @return string css setting
*/
function runtimeTaskRecurringIcon($var = '') {
if ($var != 'yes') {
return 'hidden';
}
return;
}
/**
* return formatted proposal id (e.g. PROP000024)
* @param numeric bill_invoiceid
* @return string checked | null
*/
function runtimeProposalIdFormat($proposal_id = '') {
//add the zero's
$prefix = config('system.settings_proposals_prefix');
//return
if (is_numeric($proposal_id)) {
return $prefix . str_pad($proposal_id, 5, '0', STR_PAD_LEFT);
} else {
return '---';
}
}
/**
* return formatted contract id (e.g. CONTR000024)
* @param numeric bill_invoiceid
* @return string checked | null
*/
function runtimeContractIdFormat($contract_id = '') {
//add the zero's
$prefix = config('system.settings_contracts_prefix');
//return
if (is_numeric($contract_id)) {
return $prefix . str_pad($contract_id, 5, '0', STR_PAD_LEFT);
} else {
return '---';
}
}
/**
* bootstrap class, based on value
* @param string value the status of the task
* @param string type lable|background
* @return string bootstrap label class
*/
function runtimeProposalStatusColors($value = '', $type = 'label') {
//get the settings value
switch ($value) {
case 'draft':
$colour = 'default';
break;
case 'new':
$colour = 'info';
break;
case 'accepted':
$colour = 'success';
break;
case 'declined':
$colour = 'danger';
break;
case 'revised':
$colour = 'primary';
break;
case 'expired':
$colour = 'warning';
break;
default:
$colour = 'default';
break;
}
//return the css
return bootstrapColors($colour, $type);
}
/**
* bootstrap class, based on value
* @param string value the status of the task
* @param string type lable|background
* @return string bootstrap label class
*/
function runtimeContractStatusColors($value = '', $type = 'label') {
//get the settings value
switch ($value) {
case 'draft':
$colour = 'default';
break;
case 'awaiting_signatures':
$colour = 'warning';
break;
case 'active':
$colour = 'success';
break;
case 'expired':
$colour = 'danger';
break;
default:
$colour = 'default';
break;
}
//return the css
return bootstrapColors($colour, $type);
}
/**
* return lead name with title
* @return string
*/
function runtimeLeadNameTitle($lead_firstname = '', $lead_lastname = '', $lead_title = '') {
return $lead_firstname . ' ' . $lead_lastname;
}
/**
* get the cover image for projects for task covers
* @return string
*/
function getDocumentHeroImage($directory = '', $filename = '', $updated = 'no', $type = '') {
//use image updated by the user
if ($updated == 'yes') {
if (Storage::exists("/files/$directory/$filename") && $filename != '' && $directory != '') {
return "style=\"background-image: url(storage/files/$directory/$filename)\"";
}
}
//default placeholder cover
if ($type == 'proposal') {
return "style=\"background-image: url('public/documents/images/default-background.jpg')\"";
}
//default placeholder cover
if ($type == 'contract') {
return "style=\"background-image: url('public/documents/images/default-background-contracts.jpg')\"";
}
}
/**
* set the color of text from a dbase value
* @return string
*/
function getFontColor($color = '') {
//no color
if ($color == '') {
return;
}
//default placeholder cover
return "style=\"color: $color\"";
}
/**
* check if the document is is editing mode
* @return string
*/
function documentEditingModeCheck1($mode = '') {
//no color
if ($mode == 'editing') {
return 'js-doc-editing';
}
return;
}
/**
* check if the document is is editing mode
* @return string
*/
function documentEditingModeCheck2($mode = '') {
//no color
if ($mode != 'editing') {
return 'hidden';
}
return;
}
/**
* show the correct ribbon,based on status
* @param string $value the actual value of the button (i.e. its css status)
* @param string $status the database status of the document
*/
function documentRibbonVisibility($value = 'foo', $status = 'bar') {
//hide the button
if ($value != $status) {
return 'hidden';
}
return;
}
/**
* various element visibity for estimates automation
* @param string $value determining value
*/
function estimateAutomationVisibility($value = '') {
//hide the button
if ($value == 'no' || $value == 'disabled') {
return 'hidden';
}
return;
}
/**
* various element visibity for projects automation
* @param string $value determining value
*/
function projectAutomationVisibility($value = '') {
//hide the button
if ($value == 'no' || $value == 'disabled') {
return 'hidden';
}
return;
}
/**
* various element visibity for projects automation
* @param string $value determining value
*/
function projectAutomationHourlyVisibility($value = '') {
//hide the button
if ($value != 'yes') {
return 'hidden';
}
return;
}
/**
* check if a task has a depency preventing it from being complete
* ...this will disable the checkbox for completing a task.
* @param string $value determining value
*/
function runtimeTaskDependencyLock($value = '') {
//hide the button
if ($value > 0) {
return 'disabled';
}
return;
}
/**
* show the correct label. Including the 'fulfilled' label
* @param string $value determining value
*/
function runtimeTaskDependencyColors($value = '', $status = '') {
//hide the button
if ($status == 'fulfilled') {
return 'fulfilled';
}
return $value;
}
/**
* stript tags from rish html of product items
* @param string $value determining value
*/
function runtimeProductStripTags($value = '') {
//add spaces instead of breakd and paragraphs
$value = str_replace('
', ' ', $value);
$value = str_replace('', ' ', $value);
return strip_tags($value);
}
/**
* active state for default folder
* @param string value normally coming from the database
* @return string css hidden|null
*/
function runtimeFileFoldersActive($value = '', $folder_id = 0) {
if ($folder_id > 0 && $value == $folder_id) {
return 'active';
}
}
/**
* various element visibity for projects automation
* @param string $value determining value
*/
function projectAutomationEstimateStatuses($value = '') {
//hide the button
if ($value != 'yes') {
return 'hidden';
}
return;
}
/**
* disable editing of system tax rates
* @return string
*/
function runtimeSystemTaxRate($value = '') {
if ($value == 'system') {
return 'disabled';
}
}
/**
* precheck line items tax rates
* @return string
*/
function runtimeInlineTaxPreselected($tax_taxrateid = '', $lineitem_id = '') {
//validate
if (!is_numeric($lineitem_id)) {
return;
}
//validate taxes
if (!is_numeric($tax_taxrateid)) {
return;
}
Log::info("tax_lineitem_id $lineitem_id | tax_taxrateid $tax_taxrateid");
//get taxes for this line item
if (\App\Models\Tax::Where('tax_lineitem_id', $lineitem_id)->Where('tax_taxrateid', $tax_taxrateid)->exists()) {
return 'selected';
}
}
/**
* show or hide the dimensions part of the form
* @param string $value determining value
*/
function runtimeVisibilityItemsType($value = '') {
//hide the button
if ($value != 'dimensions') {
return 'hidden';
}
return;
}
/**
* bootstrap class, based on value
* @param string value the status of the task
* @param string type lable|background
* @return string bootstrap label class
*/
function runtimeItemTypeStatusColors($value = '', $type = 'label') {
//get the settings value
switch ($value) {
case 'standard':
$colour = 'default';
break;
case 'dimensions':
$colour = 'info';
break;
default:
$colour = 'default';
break;
}
//return the css
return bootstrapColors($colour, $type);
}
/**
* enable or disablethe tax drp down, for line items that are marked as tax exempt
* @param string $value determining value
*/
function runtimeLineItemTaxStatus($value = '') {
//hide the button
if ($value == 'exempt') {
return 'disabled';
}
return;
}
/**
* dynamic url for changing bill tax type
* @param obj $bill estimate or invoice
* @return string url
*/
function runtimeBillTaxTypeURL($bill = '') {
//estimate
if ($bill->bill_type == 'estimate') {
return url('/estimates/' . $bill->bill_estimateid . '/change-tax-type');
}
//invoice
if ($bill->bill_type == 'invoice') {
return url('/invoices/' . $bill->bill_invoiceid . '/change-tax-type');
}
}
/**
* dynamic url for attaching files to invoices and estimates
* @param obj $bill estimate or invoice
* @return string url
*/
function runtimeURLBillAttachFiles($bill = '') {
//estimate
if ($bill->bill_type == 'estimate') {
return url('/estimates/' . $bill->bill_estimateid . '/attach-files');
}
//invoice
if ($bill->bill_type == 'invoice') {
return url('/invoices/' . $bill->bill_invoiceid . '/attach-files');
}
}
/**
* create a unique id to messaging links
* @param string $source unique user id
* @param string $target unique user id
* @return string url
*/
function messagesUniqueID($source = '', $target = '') {
$id = "conversation_$source" . "_" . $target;
return (str_replace('.', '_', $id));
}
/**
* create a unique id for each message
* @param string $unique_id unique message id
* @return string url
*/
function messageUniqueID($unique_id = '') {
$id = "message_id_$unique_id";
return (str_replace('.', '_', $id));
}
/**
* create a unique id for thecounter
* @param string $target unique user id
* @return string url
*/
function messagesCounterUniqueID($target = '') {
$counter = "messages_counter_$target";
return (str_replace('.', '_', $counter));
}
/**
* create a unique id for thecounter
* @param string $status users currents status
* @param string $type lang|label will create css for a label or the lang for online/offline
* @return string url
*/
function runtimeMessagesUserStatus($status = false, $type = '') {
//labels
if ($type == 'label' && $status) {
return 'text-success';
}
if ($type == 'label' && !$status) {
return 'text-muted';
}
//lang
if ($type == 'lang' && $status) {
return __('lang.online');
}
if ($type == 'lang' && !$status) {
return __('lang.offline');
}
}
/**
* return the correct css class, for a completed task
* @param numeric $status status
* @return string css class for completed task
*/
function runtimeTaskCompletedStatus($status = '') {
if ($status == 2) {
return 'task-completed';
}
}
/**
* generate the CSS ', '', $css);
return "";
}
/**
* Convert seconds to hours, minutes, seconds.
*
* @param int $seconds
* @return array
*/
function hourMinuteSeconds($duration = 0, $type = '') {
$hours = 0;
$minutes = 0;
$seconds = 0;
//avoid divisiob by zero
if ($duration > 0) {
$hours = floor($duration / 3600);
$minutes = floor(($duration / 60) % 60);
$seconds = $duration % 60;
}
switch ($type) {
case 'hours':
return $hours;
case 'minutes':
return $minutes;
case 'seconds':
return $seconds;
}
}
/**
* check if the user should see the reply editing options
*
* @param int $seconds
* @return array
*/
function permissionEditTicketReply($reply = []) {
//validate
if (!isset($reply->ticketreply_id)) {
return false;
}
//admin user
if (auth()->user()->is_admin) {
return true;
}
//team member & original poster of the reply
if (auth()->user()->is_team && $reply->ticketreply_creatorid == auth()->id()) {
return true;
}
return false;
}
/**
* check if the user should see the project billing tab
*
* @param int $seconds
* @return array
*/
function menuVisibilityProjectBillingTab() {
if (config('settings.project_permissions_view_invoices')) {
return;
}
if (auth()->user()->role->role_estimates >= 1) {
return;
}
if (config('settings.project_permissions_view_payments')) {
return;
}
if (config('settings.project_permissions_view_expenses')) {
return;
}
if (config('settings.project_permissions_view_timesheets')) {
return;
}
return 'hidden';
}
/**
* format the displayed custom field data, based on data type (e.g. date)
* @param string $value the data
* @param string $type example (date, dropdown, etc)
* @return string
*/
function runtimeCustomFieldsFormat($value = '', $type = '') {
if ($type == 'date' && $value != '') {
return runtimeDate($value);
}
//default
return $value;
}
/**
* Build a URL with optional parameters, the ability to remove specified parameters,
*
* @param array $new_params
* @param array $remove_params
* @return string
*/
function urlBuilder($new_params = [], $remove_params = []) {
// Get the current URL
$url = url()->current();
// Get the current query parameters
$current_params = request()->query();
// Remove specified parameters
if (is_array($remove_params)) {
foreach ($remove_params as $param) {
unset($current_params[$param]);
}
} elseif (is_string($remove_params)) {
unset($current_params[$remove_params]);
}
// Merge with new parameters
$params = array_merge($current_params, $new_params);
// Create the new URL
$new_url = $url . '?' . http_build_query($params);
//clean it up
$new_url = urldecode($new_url);
return $new_url;
}
/**
* check if we are truncating the string
* @param string $str
* @param int $limit
* @return string
*/
function str_limit_reports($str = '', $limit = 10) {
//check settings
if (config('system.settings2_tweak_reports_truncate_long_text') == 'yes' && is_numeric($limit)) {
return str_limit($str, $limit);
}
return $str;
}
/**
* convert month name to its numeric value
* @return string human readable time
*/
function runtimeMonthNumeric($month = '') {
$month = strtolower($month);
switch ($month) {
case 'january':
return 1;
case 'february':
return 2;
case 'march':
return 3;
case 'april':
return 4;
case 'may':
return 5;
case 'june':
return 6;
case 'july':
return 7;
case 'august':
return 8;
case 'september':
return 9;
case 'october':
return 10;
case 'november':
return 11;
case 'december':
return 12;
default:
return 0;
}
}
/**
* Show the correct email settings form
* @param string $value the data
* @param string $type example (date, dropdown, etc)
* @return string
*/
function runtimeVisibilitySection($value = '', $type = '') {
if ($value != $type) {
return 'hidden';
}
}
/**
* returns a custom field name as used in importing excel files
* @return string 'CustomField30'
*/
function customFieldImportingName($field = 'bar') {
$arr = ['client_', 'lead_', 'project_', 'task_', 'ticket_'];
$field = str_replace($arr, '', $field);
$field = str_replace('custom_', 'Custom', $field);
$field = str_replace('field_', 'Field', $field);
return $field;
}
/**
* check if a category has items and disable the cbeck box
* @return string
*/
function runtimeCategoryItemsDisabledCheck($value = '') {
if ($value == 0) {
return 'disabled';
}
}
/**
* return a name or string for unkownn/delete users
* @return string
*/
function runtimeUser($first_name = '', $last_name = '') {
if ($first_name != '' || $last_name != '') {
return $first_name . ' ' . $last_name;
}
return __('lang.unknown');
}
/**
* return the query string on the current loaded URL
* @return string
*/
function urlQuery() {
$url = parse_url(url()->full());
$query = $url['query'];
parse_str($query, $query_params);
return $query_params;
}
/**
* enable or disable the publish date
* @return string
*/
function runtimePublihItemDate($value = '') {
if ($value != 'scheduled') {
return 'disabled';
}
}
/**
* enable or disable the publish date
* @return string
*/
function runtimePublihItemButtonLang($value = '') {
if ($value == 'instant') {
return __('lang.publish');
} else {
return __('lang.schedule');
}
}
/**
* show or hide the 'set cover' link
* @return string
*/
function runtimeCoverImageAddButton($value = '', $id = '') {
if ($value == $id) {
return 'hidden';
}
}
/**
* show or hide the 'remove cover' link
* @return string
*/
function runtimeCoverImageRemoveButton($value = '', $id = '') {
if ($value != $id) {
return 'hidden';
}
}
/**
* set initial visibility of the cover image container
* @return string
*/
function runtimeKanbanCoverImage($value = '') {
if ($value != 'yes') {
return 'hidden';
}
}
/**
* set the background image using inline style css
* @return string
*/
function runtimeCoverImage($image_directory = '', $image_url = '') {
if ($image_url != '' && $image_directory != '') {
//get the url and remove spaces and clean it up
$url = url("/storage/files/$image_directory/$image_url");
$url = str_replace(' ', '%20', $url);
$url = trim($url);
return 'style="background-image: url(' . $url . ');"';
}
}
/**
* set active canned category on menu
* @return string
*/
function runtimeCannedCategory($value = '') {
if ($value == -1) {
return 'active';
}
}
/**
* set active search category on menu
* @return string
*/
function runtimeSearchCurrentMenu($menu = 'foo', $value = 'bar') {
if ($menu == $value) {
return 'active';
}
}
/**
* set the maximum results
* @return string
*/
function runtimeSearchDisplyLimit($search_type = '') {
// was the search on the 'group' screen or category screen
if ($search_type == 'all') {
return config('system.settings2_search_category_limit');
} else {
return config('system.settings_system_pagination_limits');
}
}
/**
* show or hide the sharing dropdown
* @return string
*/
function calendarSharing($sharing = '') {
if ($sharing != 'selected-users') {
return 'hidden';
}
}
/**
* various element visibity for proposals automation
* @param string $value determining value
*/
function proposalAutomationVisibility($value = '') {
//hide the button
if ($value == 'no' || $value == 'disabled') {
return 'hidden';
}
return;
}
/**
* task status name
* @param mixed $value the task status (old version of the new version based on an custom status id)
*/
function taskStatusName($value = '') {
//validate
if ($value == '') {
return '---';
}
//new status names
if (is_numeric($value)) {
$statuses = config('system.task_custom_statuses');
if (is_array($statuses) && array_key_exists($value, $statuses)) {
return $statuses[$value];
} else {
return '---';
}
}
//old name
return runtimeLang($value);
}
/**
* lead status name
* @param mixed $value the lead status (old version of the new version based on an custom status id)
*/
function leadStatusName($value = '') {
//validate
if ($value == '') {
return '---';
}
//new status names
if (is_numeric($value)) {
$statuses = config('system.lead_custom_statuses');
if (is_array($statuses) && array_key_exists($value, $statuses)) {
return $statuses[$value];
} else {
return '---';
}
}
//old name
return runtimeLang($value);
}
/**
* ticket status name
* @param mixed $value the ticket status (old version of the new version based on an custom status id)
*/
function ticketStatusName($value = '') {
//validate
if ($value == '') {
return '---';
}
//new status names
if (is_numeric($value)) {
$statuses = config('system.ticket_custom_statuses');
if (is_array($statuses) && array_key_exists($value, $statuses)) {
return $statuses[$value];
} else {
return '---';
}
}
//old name
return runtimeLang($value);
}
/**
* disabling all day checkbox for projects and tasks
* @param string $resource_type type of calendar resource
* @return string css
*/
function runtimeDisabledCalenderAllDayCheckbox($resource_type = '') {
if ($resource_type == 'project' || $resource_type == 'task') {
return 'disabled';
}
}
/**
* shows a tool tip if the event is a project or task and it can only be set as an all day
* @param string $resource_type type of calendar resource
* @return string css
*/
function runtimeDisabledCalenderAllDayTooltip($resource_type = '') {
if ($resource_type == '' || $resource_type == 'calendarevent') {
return 'hidden';
}
}
/**
* various element visibity for tickets imap settings
* @param string $value determining value
*/
function ticketsImapSettingsVisibility($value = '') {
//imap is disabled
if ($value != 'enabled') {
return 'hidden';
}
return;
}
/*
* bootstrap label class, based on user type
* @return string bootstrap label class
*/
function runtimeUserTypeLabel($type = '') {
switch ($type) {
case 'team':
return 'label-outline-info';
break;
case 'client':
return 'label-outline-success';
break;
default:
return 'label-outline-default';
break;
}
}
/**
* [modules]
* @return string a truely random unique id example: 5ed8a52d8a0b830247500
*/
function textareaFormat($name = '') {
return random_string(20) . str_unique();
}
/**
* Converts HTML content to plain text by decoding HTML entities,
* removing HTML tags, and replacing block-level elements and newlines with spaces.
*
* @param string $html The HTML content to convert.
* @return string The plain text result.
*/
function convert_html_to_plain_text($html) {
// Decode HTML entities to their corresponding characters
$text = html_entity_decode($html, ENT_QUOTES | ENT_HTML5, 'UTF-8');
// Replace block-level elements and line breaks with spaces
$search = [
'@
]*?>.*?@siu',
'@@siu',
'@@siu',
'@@siu',
'@@siu',
'@@siu',
'@]*?>.*?@siu',
'@@siu',
'@]*?>.*?@siu',
'@
]*>@siu',
'@
]*>@siu',
'@?p[^>]*>@siu',
'@?div[^>]*>@siu',
'@?li[^>]*>@siu',
'@?ul[^>]*>@siu',
'@?ol[^>]*>@siu',
'@?h[1-6][^>]*>@siu',
'@?table[^>]*>@siu',
'@?tr[^>]*>@siu',
'@?td[^>]*>@siu',
'@?th[^>]*>@siu',
'@\n@', // Newlines
'@\r@', // Carriage returns
];
$text = preg_replace($search, ' ', $text);
// Strip any remaining HTML tags
$text = strip_tags($text);
// Replace multiple whitespace characters (spaces, tabs, newlines) with a single space
$text = preg_replace('/\s+/', ' ', $text);
// Trim leading and trailing spaces
$text = trim($text);
return $text;
}
/**
* parse an email and replace placeholder {variables} with actual data
*
* @param string $content the text that has the placeholder variables. e.g. email subject or email body
* @param array $payload the payload that has the vraibles and their correspoding data
*
* @return string the content with the variables replaced with actual data
*/
function parseEmailVariables($content = '', $payload = []) {
//validate
if ($content == '' || !is_array($payload)) {
return $content;
}
//parse the content and inject actual data
$parsed = preg_replace_callback('/{(.*?)}/', function ($matches) use ($payload) {
list($shortcode, $index) = $matches;
//if shortcode is found, replace or return as is
if (isset($payload[$index])) {
return $payload[$index];
} else {
return $shortcode;
}
}, $content);
//return
return $parsed;
}
/**
* fix the name used by modules so that it only have alph numeric and is lowercase
* This is important for various ways in which the module name will be used in the CRM
* [TODO] - move this into ModulesHelper.php
*
* @param string $name the module name
*
* @return string the fixed name
*/
function modulesSanitizeModuleName($module_name = '') {
// Sanitize the module name: replace non-alphanumeric characters with underscores and convert to lowercase
$module_name = strtolower(preg_replace('/[^a-zA-Z0-9]+/', '_', $module_name));
// Remove leading/trailing underscores
$module_name = trim($module_name, '_');
return $module_name;
}