Plugin Directory

Changeset 3033873


Ignore:
Timestamp:
02/10/2024 02:10:48 AM (13 months ago)
Author:
sunnysonic
Message:
  • tested wordpress 6.4.3
  • accounting regions can now be edited by the admin through the menu
  • a tag system has been implemented
  • tags can be created through the stand-alone menu called "Tags" and applied to every client profile
  • client list can be filtered by tags now
  • open tasks dashboard widget now shows in two columns and can be filtered by due, started and all open tasks
Location:
wp-easy-crm
Files:
41 added
6 edited

Legend:

Unmodified
Added
Removed
  • wp-easy-crm/trunk/easy-crm.php

    r3031193 r3033873  
    44 * Plugin Name:       Easy CRM
    55 * Description:       Collect new leads, manage clients, quotations, invoices, tasks and more for your entire team
    6  * Version:           1.0.18
     6 * Version:           1.0.19
    77 * Author:            IT-iCO SRL
    88 * Author URI:        https://it-ico.com
     
    4747            nombrecontacto varchar(500) NOT NULL,
    4848            nota varchar(2000),
     49            tagsrelations varchar(2000),
    4950            clientsource varchar(150),
    5051            telefono varchar(500),
     
    189190
    190191
     192    $tagTable = $wpdb->prefix . 'easytags';
     193
     194    // Create tags Table if not exist
     195
     196    $sqltags = "CREATE TABLE $tagTable (
     197        id int(11) NOT NULL AUTO_INCREMENT,
     198        tagtitle varchar(200) NOT NULL,
     199        tagcolor varchar(200),
     200        created_at datetime NOT NULL,
     201        PRIMARY KEY tag_id (id)
     202    ) $charset_collate;";
     203
     204    add_option( "clients_db_version", "1.0" );
     205
     206    // Include Upgrade Script
     207    require_once( ABSPATH . '/wp-admin/includes/upgrade.php' );
     208
     209    // Create Table
     210    dbDelta( $sqltags );
     211
     212
     213
    191214
    192215    $logclientTable = $wpdb->prefix . 'logclient';
     
    215238        dbDelta( $sqllog );
    216239
    217 
    218 
    219 
    220 
    221240}
    222241function eacr_uninstall() {
     
    232251    $logclientTable = $wpdb->prefix . 'logclient';
    233252    $accountingregionTable = $wpdb->prefix . 'eacraccountingregion';
     253    $tagTable = $wpdb->prefix . 'easytags';
     254
    234255
    235256    $wpdb->query( "DROP TABLE IF EXISTS $quoteLineclientTable" );
     
    249270
    250271    $wpdb->query( "DROP TABLE IF EXISTS $accountingregionTable" );
     272    delete_option("clients_db_version");
     273
     274    $wpdb->query( "DROP TABLE IF EXISTS $tagTable" );
    251275    delete_option("clients_db_version");
    252276
     
    478502    $taskTable = $wpdb->prefix . 'task';
    479503    $clientTable = $wpdb->prefix . 'clients';
     504   
     505    // Add buttons to filter tasks
     506    echo '
     507    <div style="margin-bottom: 10px;">
     508        <button onclick="filterTasks(\'started\')">Show Started Tasks</button>
     509        <button onclick="filterTasks(\'due\')">Show Due Tasks</button>
     510        <button onclick="filterTasks(\'all\')">Show All Open Tasks</button>
     511    </div>
     512    ';
     513
     514    // JavaScript function to filter tasks
     515    echo '
     516    <script>
     517    function filterTasks(type) {
     518        // Get all task cards
     519        var tasks = document.getElementsByClassName("task-card");
     520
     521        // Loop through all task cards
     522        for (var i = 0; i < tasks.length; i++) {
     523            var task = tasks[i];
     524            var start = task.dataset.start;
     525            var end = task.dataset.end;
     526
     527            // Show or hide task cards based on filter type
     528            if (type === "started" && new Date(start) > new Date()) {
     529                task.style.display = "none";
     530            } else if (type === "due" && new Date(end) > new Date()) {
     531                task.style.display = "none";
     532            } else if (type === "all") {
     533                task.style.display = "block";
     534            } else {
     535                task.style.display = "block";
     536            }
     537        }
     538    }
     539    </script>
     540    ';
     541
     542    // Fetch tasks based on filter (not implemented yet)
    480543    $allmyopentasks = $wpdb->get_results(
    481544        $wpdb->prepare(
    482             "SELECT * from $taskTable WHERE useridfk = %d AND completed = 0 ORDER BY created_at DESC",$myuserid
    483         ),ARRAY_A
     545            "SELECT * FROM $taskTable WHERE useridfk = %d AND completed = 0 ORDER BY created_at DESC", $myuserid
     546        ), ARRAY_A
    484547    );
    485        
     548   
     549    // Add CSS for two-column layout and task card width adjustment
     550    echo "
     551    <style>
     552        /* CSS for two-column layout */
     553        .task-container {
     554            display: grid;
     555            grid-template-columns: repeat(2, 1fr); /* Two columns with equal width */
     556            gap: 10px; /* Smaller gap between tasks */
     557        }
     558
     559        .task-card {
     560            box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2);
     561            transition: 0.3s;
     562            border-radius: 5px;
     563            background-color: #e0e4cc;
     564            /* Limit task card width to fit within the widget space */
     565            /*max-width: calc(50% - 10px);  Adjust according to your widget space and gap */
     566            padding: 20px; /* Moved padding from .task-card to .task-container */
     567            margin-bottom: 10px; /* Added margin to create space between tasks */
     568        }
     569
     570        .task-title {
     571            font-size: 16px;
     572            margin-bottom: 10px; /* Added margin to create space between title and button */
     573        }
     574
     575        .task-buttons {
     576            display: flex;
     577            align-items: center;
     578        }
     579
     580        .task-buttons a {
     581            margin-left: 10px; /* Added margin between buttons */
     582        }
     583    </style>
     584    ";
     585
    486586    if(count($allmyopentasks) > 0){
     587        // Wrap tasks in a container with two columns
     588        echo '<div class="task-container">';
     589       
    487590        // Reverse the order of tasks
    488591        $reversedTasks = array_reverse($allmyopentasks);
    489592        foreach($reversedTasks as $singletask){
    490593            // Start of card container with shadow, padding, and margin for card-like appearance
    491             echo '<div style="box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2); transition: 0.3s; border-radius: 5px; margin: 5px; margin-bottom:15px; padding: 20px; background-color: #e0e4cc;">';
     594            echo '<div class="task-card" data-start="' . $singletask['start_at'] . '" data-end="' . $singletask['end_at'] . '">';
    492595   
    493596                // Title and button container
    494                 echo '<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px;">';
    495                     // Task title
    496                     echo '<div style="flex-grow: 1; font-size: 16px;"><b> # '.esc_html($singletask['tasktitle']).'</b></div>';
    497    
     597                echo '<div class="task-title"><b> # '.esc_html($singletask['tasktitle']).'</b></div>';
     598                echo '<div class="task-buttons">';
    498599                    // Buttons and client name
    499600                    $clientid = sanitize_text_field($singletask['clientidfk']);
     
    502603                        $clientdetails = $wpdb->get_row($wpdb->prepare("SELECT * FROM $clientTable WHERE id = %d", $clientid));
    503604                        $clientname = $clientdetails->clientname;
    504                         echo '<div><a class="button button-secondary" href="admin.php?page=wp-easy-crm-perfil&id='.$clientid.'">'.$clientname.'</a><span> </span></div>';
     605                        echo '<a class="button button-secondary" href="admin.php?page=wp-easy-crm-perfil&id='.$clientid.'">'.$clientname.'</a>';
    505606                    } else {
    506                         echo '<div><a class="button button-secondary" href="admin.php?page=wp-easy-crm-tasks">'.__('Tasks', 'wp-easy-crm').'</a><span> </span></div>';
     607                        echo '<a class="button button-secondary" href="admin.php?page=wp-easy-crm-tasks">'.__('Tasks', 'wp-easy-crm').'</a>';
    507608                    }
    508                 echo '</div>'; // End of title and button container
     609                echo '</div>'; // End of button container
    509610
    510611                // Date information included within the main card container
     
    516617                echo '<div style="padding: 10px; background-color: #F2F2F2; border-radius: 5px; margin-top: 10px;">'; // Added margin-top for spacing
    517618                if ($startDateTime <= $currentDateTime) {
    518                     echo '<span style="color: rgba(255, 0, 0, 0.5);font-weight: bold; font-size: 13px;">Start: ' . htmlspecialchars($startDateTime->format('Y-m-d')) . '</span>';
     619                    echo '<span style="color: rgba(255, 0, 0, 0.5);font-weight: bold; font-size: 11px;">Start: ' . htmlspecialchars($startDateTime->format('Y-m-d')) . '</span>';
    519620                } else {
    520                     echo '<span style="color: grey;font-size: 13px;">Start: ' . htmlspecialchars($startDateTime->format('Y-m-d')) . '</span>';
     621                    echo '<span style="color: grey;font-size: 11px;">Start: ' . htmlspecialchars($startDateTime->format('Y-m-d')) . '</span>';
    521622                }
    522623   
    523624                if ($endDateTime <= $currentDateTime) {
    524                     echo '<span style="color: rgba(255, 0, 0, 0.5);font-weight: bold;margin-left: 1em;font-size: 13px;">Due: ' . htmlspecialchars($endDateTime->format('Y-m-d')) . '</span>';
     625                    echo '<span style="color: rgba(255, 0, 0, 0.5);font-weight: bold;margin-left: 1em;font-size: 11px;">Due: ' . htmlspecialchars($endDateTime->format('Y-m-d')) . '</span>';
    525626                } else {
    526                     echo '<span style="color: grey;margin-left: 1em;font-size: 13px;">Due: ' . htmlspecialchars($endDateTime->format('Y-m-d')) . '</span>';
     627                    echo '<span style="color: grey;margin-left: 1em;font-size: 11px;">Due: ' . htmlspecialchars($endDateTime->format('Y-m-d')) . '</span>';
    527628                }
    528629                echo '</div>'; // End of date information container
    529    
     630
    530631                // Task description
    531632                echo '<div>'.wp_kses_post($singletask['taskdescription']).'</div>';
    532633   
    533                
    534    
    535634            echo '</div>'; // End of the main card container
    536635            //echo '<hr/>'; // Separator (consider styling or removing for spacing)
    537636        }
    538     }
    539    
    540    
    541    
    542        
    543 
    544     // echo '<div class="eacr-dashboard-widget">Hello, world!</div>';
    545 }
     637       
     638        echo '</div>'; // End of task container
     639    }
     640}
     641
     642
    546643 
    547644  function eacr_register_dashboard_widget() {
     
    611708    add_submenu_page("wp-easy-crm","Tasks",__('Tasks', 'wp-easy-crm'),"edit_others_posts","wp-easy-crm-tasks","eacr_tasks_call");
    612709    add_submenu_page("wp-easy-crm","Quotes / Invoices",__('Quotes / Invoices', 'wp-easy-crm'),"edit_others_posts","wp-easy-crm-quotes","eacr_quotes_call");
     710    add_submenu_page("wp-easy-crm","Tags",__('Tags', 'wp-easy-crm'),"edit_others_posts","wp-easy-crm-tags","eacr_tags_call");
    613711    add_submenu_page("wp-easy-crm","Forms",__('Forms', 'wp-easy-crm'),"edit_others_posts","wp-easy-crm-forms","eacr_forms_call");
    614712    add_submenu_page("wp-easy-crm","Settings",__('Settings', 'wp-easy-crm'),"manage_options","wp-easy-crm-settings","eacr_settings_call");
     713    add_submenu_page("wp-easy-crm","Accounting Regions",__('Accounting Regions', 'wp-easy-crm'),"manage_options","wp-easy-crm-accregions","eacr_accregions_call");
     714
    615715
    616716
     
    626726}
    627727
     728function eacr_accregions_call(){
     729
     730    include_once EASYCRM_PLUGIN_DIR_PATH.'/views/accountingregions.php';
     731}
     732
     733function eacr_tags_call(){
     734
     735    include_once EASYCRM_PLUGIN_DIR_PATH.'/views/tagsView.php';
     736}
    628737
    629738function eacr_client_quoteview_call(){
  • wp-easy-crm/trunk/readme.txt

    r3031193 r3033873  
    44Requires at least: 5.9
    55Tested up to: 6.4.3
    6 Stable tag: 1.0.18
     6Stable tag: 1.0.19
    77Contributors: sunnysonic
    88License: GPLv2 or later
     
    6060
    6161== Changelog ==
     62
     63= 1.0.19 =
     64* tested wordpress 6.4.3
     65* accounting regions can now be edited by the admin through the menu
     66* a tag system has been implemented
     67* tags can be created through the stand-alone menu called "Tags" and applied to every client profile
     68* client list can be filtered by tags now
     69* open tasks dashboard widget now shows in two columns and can be filtered by due, started and all open tasks
    6270
    6371= 1.0.18 =
  • wp-easy-crm/trunk/views/addClient.php

    r3024884 r3033873  
    1010$id = sanitize_text_field(isset($_GET['id']) ? intval($_GET['id']) : "");
    1111
    12 
    13 
    14 
    1512if(isset($_POST['btnsubmit'])){
    1613   
     
    1916
    2017    if(!empty($action)){
    21         //update client
    22         $wpdb->update($clientTable,array(
    23             "clientname" => sanitize_text_field(wp_unslash($_POST['clientname'])),
    24             "clientstatus" => sanitize_text_field(wp_unslash($_POST['clientstatus'])),
    25             "email" => sanitize_text_field(wp_unslash($_POST['email'])),
    26             "nombrecontacto" => sanitize_text_field(wp_unslash($_POST['nombrecontacto'])),
    27             "nota" => sanitize_text_field(wp_unslash($_POST['nota'])),
    28             "telefono" => sanitize_text_field(wp_unslash($_POST['telefono'])),
    29             "clientsource" => sanitize_text_field(wp_unslash($_POST['clientsource'])),
    30             "provincia" => sanitize_text_field(wp_unslash($_POST['provincia'])),
    31             "direccion" => sanitize_text_field(wp_unslash($_POST['direccion'])),
    32             "lastupdate_at" => sanitize_text_field(wp_unslash($_POST['lastupdate_at'])),
    33             "idaccountingregionfk" => sanitize_text_field(wp_unslash($_POST['idaccountingregionfk'])),
    34             "created_at" => sanitize_text_field(wp_unslash($_POST['created_at']))
    35         ), array(
    36            "id" => $id
    37         ));
    38         $msg = "<div class='updated update'>" . __( 'Client successfully updated. You will be redirected to the client profile in 2 seconds automatically.', 'wp-easy-crm' ) . "</div>";
    39 
    40         // Construct the redirect URL dynamically to client profile
    41         $redirect_url = admin_url('admin.php?page=wp-easy-crm-perfil&id=' . $id);
    42 
    43         // JavaScript for delay and redirection
    44         echo "<script>
    45             setTimeout(function() {
    46                 window.location.href = '" . $redirect_url . "';
    47             }, 2000);
    48         </script>";
    49 
     18        // Update client
     19
     20        // Fetch existing emails associated with the client being updated
     21        $existing_emails_for_client = $wpdb->get_var(
     22            $wpdb->prepare(
     23                "SELECT email FROM $clientTable WHERE id = %d", $id
     24            )
     25        );
     26
     27        // Split existing emails into an array
     28        $existing_emails_for_client = explode(',', $existing_emails_for_client);
     29
     30        // Initialize an array to store new emails for the client
     31        $new_emails = array();
     32
     33        // Retrieve entered emails and split them by comma
     34        $entered_emails = isset($_POST['email']) ? sanitize_text_field($_POST['email']) : '';
     35        $emails_array = explode(',', $entered_emails);
     36        $existing_emails = array();
     37
     38        // Check each email against the database, excluding the current client being updated
     39        foreach ($emails_array as $email) {
     40            // Trim the email
     41            $trimmed_email = trim($email);
     42           
     43            // Check if the trimmed email is not empty
     44            if (!empty($trimmed_email)) {
     45                // If the email is not associated with the client being updated
     46                if (!in_array($trimmed_email, $existing_emails_for_client)) {
     47                    // Add it to the new emails array for further processing
     48                    $new_emails[] = $trimmed_email;
     49                }
     50            }
     51        }
     52
     53        // Initialize an array to store existing emails for other clients
     54        $existing_emails = array();
     55
     56        // Check each new email against the database for duplication
     57        foreach ($new_emails as $new_email) {
     58            // Split the new email into an array in case it contains multiple emails
     59            $new_email_array = explode(',', $new_email);
     60
     61            // Check each individual email
     62            foreach ($new_email_array as $individual_email) {
     63                // If the email already exists for another client
     64                $existing_client = $wpdb->get_row(
     65                    $wpdb->prepare(
     66                        "SELECT * FROM $clientTable WHERE email LIKE %s AND id != %d", '%' . trim($individual_email) . '%', $id
     67                    ), ARRAY_A
     68                );
     69               
     70                // If an existing client is found, add the email to the existing emails array
     71                if ($existing_client) {
     72                    $existing_emails[] = trim($individual_email);
     73                }
     74            }
     75        }
     76       
     77        // If there are existing emails, display an alert
     78        if (!empty($existing_emails)) {
     79            $msg = "<div style='color:red'>".esc_html(__( 'Error - the following email(s) already exist in the database for other clients: ', 'wp-easy-crm' ));
     80            foreach ($existing_emails as $existing_email) {
     81                $msg .= $existing_email . ', ';
     82            }
     83            $msg = rtrim($msg, ', '); // Remove trailing comma
     84            $msg .= ". Please search for those emails in the client-list and add your data to the existing client files.</div>";
     85        } else {
     86            // Continue updating the client
     87            $wpdb->update($clientTable,array(
     88                "clientname" => sanitize_text_field(wp_unslash($_POST['clientname'])),
     89                "clientstatus" => sanitize_text_field(wp_unslash($_POST['clientstatus'])),
     90                "email" => sanitize_text_field(wp_unslash($_POST['email'])),
     91                "nombrecontacto" => sanitize_text_field(wp_unslash($_POST['nombrecontacto'])),
     92                "nota" => sanitize_text_field(wp_unslash($_POST['nota'])),
     93                "telefono" => sanitize_text_field(wp_unslash($_POST['telefono'])),
     94                "clientsource" => sanitize_text_field(wp_unslash($_POST['clientsource'])),
     95                "provincia" => sanitize_text_field(wp_unslash($_POST['provincia'])),
     96                "direccion" => sanitize_text_field(wp_unslash($_POST['direccion'])),
     97                "lastupdate_at" => sanitize_text_field(wp_unslash($_POST['lastupdate_at'])),
     98                "idaccountingregionfk" => sanitize_text_field(wp_unslash($_POST['idaccountingregionfk'])),
     99                "created_at" => sanitize_text_field(wp_unslash($_POST['created_at']))
     100            ), array(
     101               "id" => $id
     102            ));
     103            $msg = "<div class='updated update'>" . __( 'Client successfully updated. You will be redirected to the client profile in 2 seconds automatically.', 'wp-easy-crm' ) . "</div>";
     104   
     105            // Construct the redirect URL dynamically to client profile
     106            $redirect_url = admin_url('admin.php?page=wp-easy-crm-perfil&id=' . $id);
     107   
     108            // JavaScript for delay and redirection
     109            echo "<script>
     110                setTimeout(function() {
     111                    window.location.href = '" . $redirect_url . "';
     112                }, 2000);
     113            </script>";
     114        }
     115
     116    } else {
     117        // Add new client
     118
     119        // Retrieve entered emails and split them by comma
     120        $entered_emails = isset($_POST['email']) ? sanitize_text_field($_POST['email']) : '';
     121        $emails_array = explode(',', $entered_emails);
     122        $existing_emails = array();
     123
     124        // Check each email against the database
     125        foreach ($emails_array as $email) {
     126            $existing_client = $wpdb->get_row(
     127                $wpdb->prepare(
     128                    "SELECT * FROM $clientTable WHERE email = %s", trim($email)
     129                ), ARRAY_A
     130            );
     131            if ($existing_client) {
     132                $existing_emails[] = $email;
     133            }
     134        }
     135
     136        // If there are existing emails, display an alert
     137        if (!empty($existing_emails)) {
     138            $msg = "<div style='color:red'>".esc_html(__( 'Error - the following email(s) already exist in the database: ', 'wp-easy-crm' ));
     139            foreach ($existing_emails as $existing_email) {
     140                $msg .= $existing_email . ', ';
     141            }
     142            $msg = rtrim($msg, ', '); // Remove trailing comma
     143            $msg .= ". Please search for that email in the client-list and add your data to the existing client file.</div>";
     144        } else {
     145            // Continue adding the new client
     146            $wpdb->insert($clientTable,array(
     147                "clientname"=>sanitize_text_field($_POST['clientname']),
     148                "clientstatus"=>sanitize_text_field($_POST['clientstatus']),
     149                "email"=>sanitize_text_field($_POST['email']),
     150                "nombrecontacto"=>sanitize_text_field($_POST['nombrecontacto']),
     151                "nota"=>sanitize_text_field($_POST['nota']),
     152                "telefono"=>sanitize_text_field($_POST['telefono']),
     153                "clientsource"=>sanitize_text_field($_POST['clientsource']),
     154                "provincia"=>sanitize_text_field($_POST['provincia']),
     155                "direccion"=>sanitize_text_field($_POST['direccion']),
     156                "lastupdate_at"=>sanitize_text_field($_POST['lastupdate_at']),
     157                "idaccountingregionfk" => sanitize_text_field(wp_unslash($_POST['idaccountingregionfk'])),
     158                "created_at"=>sanitize_text_field($_POST['created_at'])
     159            ));
     160            if($wpdb->insert_id > 0){
     161                $msg = "<div class='updated update'>".esc_html(__( 'client successfully saved. You will be redirected to the client profile in 2 seconds automatically.', 'wp-easy-crm' ))."</div>";
     162       
     163                // Construct the redirect URL dynamically to client profile
     164                $redirect_url = admin_url('admin.php?page=wp-easy-crm-perfil&id=' . $wpdb->insert_id);
     165       
     166                // JavaScript for delay and redirection
     167                echo "<script>
     168                    setTimeout(function() {
     169                        window.location.href = '" . $redirect_url . "';
     170                    }, 2000);
     171                </script>";
     172       
     173            }else{
     174                $msg = "<div style='color:red'>".esc_html(__( 'error - client information couldn\'t be stored', 'wp-easy-crm' ))."</div>";
     175            }
     176        }
    50177    }
    51     else{
    52         //add new client
    53     $wpdb->insert($clientTable,array(
    54         "clientname"=>sanitize_text_field($_POST['clientname']),
    55         "clientstatus"=>sanitize_text_field($_POST['clientstatus']),
    56         "email"=>sanitize_text_field($_POST['email']),
    57         "nombrecontacto"=>sanitize_text_field($_POST['nombrecontacto']),
    58         "nota"=>sanitize_text_field($_POST['nota']),
    59         "telefono"=>sanitize_text_field($_POST['telefono']),
    60         "clientsource"=>sanitize_text_field($_POST['clientsource']),
    61         "provincia"=>sanitize_text_field($_POST['provincia']),
    62         "direccion"=>sanitize_text_field($_POST['direccion']),
    63         "lastupdate_at"=>sanitize_text_field($_POST['lastupdate_at']),
    64         "idaccountingregionfk" => sanitize_text_field(wp_unslash($_POST['idaccountingregionfk'])),
    65         "created_at"=>sanitize_text_field($_POST['created_at'])
    66     ));
    67     if($wpdb->insert_id > 0){
    68         $msg = "<div class='updated update'>".esc_html(__( 'client successfully saved', 'wp-easy-crm' ))."</div>";
    69 
    70     }else{
    71         $msg = "<div style='color:red'>".esc_html(__( 'error - client information couldn\'t be stored', 'wp-easy-crm' ))."</div>";
    72     }
    73 
    74 
    75     }
    76 
    77    
    78 
    79178}
    80179
     
    84183    ),ARRAY_A
    85184);
    86 
    87 
    88185
    89186?>
     
    112209    <select name="clientstatus" required>
    113210        <option value="<?php echo esc_html(isset($row_details['clientstatus']) ? $row_details['clientstatus'] : ""); ?>"><?php echo esc_html(isset($row_details['clientstatus']) ? $row_details['clientstatus'] : _e( 'Choose client status', 'wp-easy-crm' ))?></option>
    114         <option value="lead">"<?php _e( "Lead", 'wp-easy-crm' );?>"</option>
    115         <option value="customer">"<?php _e( 'Customer', 'wp-easy-crm' );?>"</option>
    116         <option value="refused">"<?php _e( 'Refused', 'wp-easy-crm' );?>"</option>
    117         <option value="blacklisted">"<?php _e( 'Blacklisted', 'wp-easy-crm' );?>"</option>
     211        <option value="lead"><?php _e( "Lead", 'wp-easy-crm' );?></option>
     212        <option value="customer"><?php _e( 'Customer', 'wp-easy-crm' );?></option>
     213        <option value="refused"><?php _e( 'Refused', 'wp-easy-crm' );?></option>
     214        <option value="blacklisted"><?php _e( 'Blacklisted', 'wp-easy-crm' );?></option>
    118215
    119216    </select>
     
    128225    <select name="clientsource" required>
    129226        <option value="<?php echo esc_html(isset($row_details['clientsource']) ? $row_details['clientsource'] : ""); ?>"><?php echo esc_html(isset($row_details['clientsource']) ? $row_details['clientsource'] : _e( 'Choose client source', 'wp-easy-crm' ))?></option>
    130         <option value="website">"<?php _e( "Website", 'wp-easy-crm' );?>"</option>
    131         <option value="email">"<?php _e( 'Email', 'wp-easy-crm' );?>"</option>
    132         <option value="call">"<?php _e( 'Call', 'wp-easy-crm' );?>"</option>
    133         <option value="social media">"<?php _e( 'Social Media', 'wp-easy-crm' );?>"</option>
    134         <option value="recommendation">"<?php _e( 'Recommendation', 'wp-easy-crm' );?>"</option>
    135         <option value="other">"<?php _e( 'Other', 'wp-easy-crm' );?>"</option>
     227        <option value="website"><?php _e( "Website", 'wp-easy-crm' );?></option>
     228        <option value="email"><?php _e( 'Email', 'wp-easy-crm' );?></option>
     229        <option value="call"><?php _e( 'Call', 'wp-easy-crm' );?></option>
     230        <option value="social media"><?php _e( 'Social Media', 'wp-easy-crm' );?></option>
     231        <option value="recommendation"><?php _e( 'Recommendation', 'wp-easy-crm' );?></option>
     232        <option value="other"><?php _e( 'Other', 'wp-easy-crm' );?></option>
    136233    </select>
    137234
     
    203300
    204301</form>
    205 
    206 
  • wp-easy-crm/trunk/views/addTask.php

    r3031193 r3033873  
    125125    $taskdescription = wpautop($_POST['taskdescription']);
    126126
     127    $row_details_client = $wpdb->get_row(
     128        $wpdb->prepare(
     129            "SELECT * from $clientTable WHERE id = %d",$id
     130        ),ARRAY_A
     131    );
     132   
    127133 
    128134    if(!empty($action)){
     
    172178            $user_data = get_userdata(sanitize_text_field($_POST['useridfk']));
    173179            $to = $user_data->user_email;
    174             $subject = __('A task was edited for you', 'wp-easy-crm' );
     180            if (isset($row_details_client['clientname']) && is_string($row_details_client['clientname'])) {
     181                // $row_details_client is not empty, process the data
     182                $subject = __('A task was edited for you for client: ', 'wp-easy-crm' ).$row_details_client['clientname'];
     183            } else {
     184                // $row_details_client is empty, handle the case where no data was found
     185                $subject = __('A task was edited for you', 'wp-easy-crm' );
     186            }
    175187            $message = __('The Task Title is: ', 'wp-easy-crm') .sanitize_text_field($_POST['tasktitle']);
    176188            $headers = array('From: Easy CRM '.esc_html($domain_name).' <wordpress@'.esc_html($domain_name).'>', 'Content-Type: text/html; charset=UTF-8');
     
    185197    else{
    186198        // Allowed HTML tags and attributes
    187        
    188        
    189 
     199     
    190200
    191201        $taskdescription = wpautop($_POST['taskdescription']);
     
    223233            $user_data = get_userdata($_POST['useridfk']);
    224234            $to = $user_data->user_email;
    225             $subject = __('A new task was added for you', 'wp-easy-crm' );
     235            if (isset($row_details_client['clientname']) && is_string($row_details_client['clientname'])) {
     236                // $row_details_client is not empty, process the data
     237                $subject = __('A new task was added for you for client: ', 'wp-easy-crm' ).$row_details_client['clientname'];
     238            } else {
     239                // $row_details_client is empty, handle the case where no data was found
     240                $subject = __('A new task was added for you', 'wp-easy-crm' );
     241            }
     242           
    226243            $message = __('The Task Title is: ', 'wp-easy-crm') .sanitize_text_field($_POST['tasktitle']);
    227244            $headers = array('From: Easy CRM '.esc_html($domain_name).' <wordpress@'.esc_html($domain_name).'>', 'Content-Type: text/html; charset=UTF-8');
  • wp-easy-crm/trunk/views/clientProfile.php

    r3031193 r3033873  
    153153?> <b><?php _e( 'Contact(s):', 'wp-easy-crm' );?></b> <?php echo esc_html($row_details['nombrecontacto']) ?> <b>Email(s):</b> <?php echo esc_html($row_details['email']) ?> <b><?php _e( 'Telephone(s):', 'wp-easy-crm' );?></b> <?php echo $row_details['telefono'] ?> <b><?php _e( 'State:', 'wp-easy-crm' );?></b> <?php echo $row_details['provincia'] ?></code>
    154154</br></br><code><b><?php _e( 'Address:', 'wp-easy-crm' );?></b> <?php echo esc_html($row_details['direccion']) ?> <b>Accounting Region:</b> <?php echo esc_html($accountingRegionName) ?> </code>
    155 </br></br><code><b><?php _e( 'Note:', 'wp-easy-crm' );?></b> <?php echo esc_html($row_details['nota']) ?></code>
     155</br></br><code><b><?php _e( 'Note:', 'wp-easy-crm' );?></b> <?php echo esc_html($row_details['nota']) ?></code><br/><br/>
     156<b> <?php _e( 'Tags: ', 'wp-easy-crm' );?></b><?php echoTagsStuff($row_details); //add tags menu and pass client data ?>
    156157
    157158<style>
     
    469470</script>
    470471
     472<?php
     473
     474//this section echos all the hashtag section in the client profile menu
     475function echoTagsStuff($clientdata) {
     476    global $wpdb;
     477    $tagTable = $wpdb->prefix . 'easytags';
     478    $clientTable = $wpdb->prefix . 'clients';
     479    $clientId = isset($clientdata['id']) ? $clientdata['id'] : 0;
     480    $currentTagsIds = !empty($clientdata['tagsrelations']) ? explode(',', $clientdata['tagsrelations']) : [];
     481
     482    // Handle tag deletion
     483    if (isset($_POST['delete_tag'], $_POST['tag_id'], $_POST['_wpnonce_delete_tag']) && wp_verify_nonce($_POST['_wpnonce_delete_tag'], 'delete_tag_action')) {
     484        $tagIdToDelete = intval($_POST['tag_id']);
     485        if (($key = array_search($tagIdToDelete, $currentTagsIds)) !== false) {
     486            unset($currentTagsIds[$key]);
     487            $newTagsIds = implode(',', $currentTagsIds);
     488            $wpdb->update($clientTable, ['tagsrelations' => $newTagsIds], ['id' => $clientId]);
     489            echo "<script>window.location.reload();</script>";
     490        }
     491    }
     492
     493    // Handle adding a new tag
     494    if (isset($_POST['add_tag'], $_POST['new_tag_id'], $_POST['_wpnonce_add_new_tag']) && wp_verify_nonce($_POST['_wpnonce_add_new_tag'], 'add_new_tag_action')) {
     495        $newTagId = intval($_POST['new_tag_id']);
     496        if (!in_array($newTagId, $currentTagsIds)) {
     497            $currentTagsIds[] = $newTagId;
     498            $newTagsIds = implode(',', $currentTagsIds);
     499            $wpdb->update($clientTable, ['tagsrelations' => $newTagsIds], ['id' => $clientId]);
     500            echo "<script>window.location.reload();</script>";
     501        }
     502    }
     503
     504    // Fetch and display current tags
     505    if (!empty($currentTagsIds)) {
     506        $placeholders = implode(',', array_fill(0, count($currentTagsIds), '%d'));
     507        $tags = $wpdb->get_results($wpdb->prepare("SELECT id, tagtitle, tagcolor FROM $tagTable WHERE id IN ($placeholders)", $currentTagsIds));
     508        foreach ($tags as $tag) {
     509            echo '<div class="tag-bubble" style="background-color:' . esc_attr($tag->tagcolor) . '; color: #ffffff;">';
     510            echo '#' . esc_html($tag->tagtitle);
     511            echo '<form method="post" action="" style="display:inline;"><input type="hidden" name="tag_id" value="' . esc_attr($tag->id) . '"><input type="hidden" name="delete_tag" value="1"><input type="hidden" name="_wpnonce_delete_tag" value="' . wp_create_nonce('delete_tag_action') . '"><button type="submit" class="tag-delete">X</button></form>';
     512            echo '</div>';
     513        }
     514    }
     515
     516    // Collapsible Add Tag Form
     517    echo '<div id="addTagButton" style="cursor: pointer; display: inline-block; margin-left: 20px; font-size: 24px;">+</div>';
     518    echo '<div id="addTagForm" style="display: none; margin-top: 10px;">';
     519    echo '<form method="post" action="">';
     520    echo '<select name="new_tag_id"><option value="">Select a tag to add</option>';
     521    $allTags = $wpdb->get_results("SELECT id, tagtitle FROM $tagTable");
     522    foreach ($allTags as $tag) {
     523        if (!in_array($tag->id, $currentTagsIds)) {
     524            echo '<option value="' . esc_attr($tag->id) . '">' . esc_html($tag->tagtitle) . '</option>';
     525        }
     526    }
     527    echo '</select>';
     528    echo '<input type="hidden" name="add_tag" value="1">';
     529    echo wp_nonce_field('add_new_tag_action', '_wpnonce_add_new_tag', true, false);
     530    echo '<input type="submit" value="Add Tag">';
     531    echo '</form></div>';
     532
     533    // JavaScript for collapsible form
     534    echo '<script>
     535    jQuery(document).ready(function($) {
     536        $("#addTagButton").click(function() {
     537            $("#addTagForm").slideToggle();
     538        });
     539    });
     540    </script>';
     541
     542    // Styling
     543echo '<style>
     544.tag-bubble {
     545    display: inline-block;
     546    border-radius: 15px;
     547    padding: 5px 10px;
     548    margin: 5px;
     549    cursor: pointer;
     550    font-weight: bold;
     551    background-color: #ffffff;
     552    color: #ffffff;
     553    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
     554    letter-spacing: 2px; /* Increased letter spacing */
     555}
     556.tag-delete {
     557    margin-left: 8px;
     558    color: #000000;
     559    cursor: pointer;
     560}
     561#addTagButton {
     562    background-color: #f0f0f0;
     563    padding: 8px; /* Reduced padding for a smaller circle */
     564    border-radius: 50%;
     565    width: 24px; /* Reduced width for a smaller circle */
     566    height: 24px; /* Reduced height for a smaller circle */
     567    text-align: center;
     568    line-height: 8px; /* Adjust line height for vertical alignment */
     569    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
     570    cursor: pointer;
     571}
     572#addTagForm select, #addTagForm input[type="submit"] {
     573    margin-top: 5px;
     574}
     575</style>';
     576}
     577
     578
     579
     580
     581
     582
     583
     584
     585?>
     586
    471587<!-- Hook for Projects and other modules to be added -->
    472588<?php
  • wp-easy-crm/trunk/views/listClients.php

    r3031193 r3033873  
    1111$accregionTable = $wpdb->prefix . 'eacraccountingregion';
    1212$projectsTable = $wpdb->prefix . 'easyprojects';
     13$tagTable = $wpdb->prefix . 'easytags';
    1314
    1415
     
    184185    // echo "Table with clients does not exist.";
    185186}
     187}
     188
     189
     190// Assuming $tagTable is defined and contains the name of your tag table
     191$allTags = $wpdb->get_results("SELECT * FROM $tagTable ORDER BY tagtitle ASC");
     192$tagMap = [];
     193foreach ($allTags as $tag) {
     194    // Assuming $tag->id, $tag->tagtitle, and $tag->tagcolor are the properties
     195    $tagMap[$tag->id] = $tag;
    186196}
    187197
     
    300310        // Initialize your DataTable
    301311        var table = $('#clientstable').DataTable({
    302             order: [[7, 'desc']],
     312            order: [[8, 'desc']],
    303313            "pageLength": 12, // Default number of rows to display
    304314            "lengthMenu": [[10, 25, 50, 100, -1], [10, 25, 50, 100, "All"]], // Page length options (including 'All')
     
    310320                },
    311321                {
    312                     "targets": 8, // Index of the 9th column (Region ID)
     322                    "targets": 9, // Index of the 9th column (Region ID)
    313323                    "visible": false // Hide the column
    314324                }
     
    360370            } else {
    361371                // Filter DataTables rows based on the region ID
    362                 // Assumes the region ID is in a specific column (e.g., column index 8)
    363                 table.column(8).search(regionId).draw();
     372                // Assumes the region ID is in a specific column (e.g., column index 9)
     373                table.column(9).search(regionId).draw();
    364374            }
    365375        });
    366376
     377        jQuery('#filterbytags').click(function(e) {
     378        e.preventDefault();
     379        jQuery(this).toggleClass('show-menu');
     380        jQuery('#tagFilterContainer').slideToggle();
     381       
     382
    367383    });
     384
     385// Filter button click event handler
     386jQuery('#applyTagFilter').click(function() {
     387    // Get an array of selected tag IDs
     388    var selectedTags = jQuery('input[name="tags[]"]:checked').map(function() {
     389        return jQuery(this).val();
     390    }).get();
     391
     392    // Clear any previous custom search function
     393    jQuery.fn.dataTable.ext.search = [];
     394
     395    if (selectedTags.length > 0) {
     396        // Use custom filtering function to check if any of the selected tags match the tags associated with each row
     397        jQuery.fn.dataTable.ext.search.push(
     398            function(settings, data, dataIndex) {
     399                var rowTags = jQuery(table.row(dataIndex).node()).find('.column-columnname span[data-tagid]').map(function() {
     400                    return jQuery(this).data('tagid').toString();
     401                }).get();
     402
     403                return selectedTags.every(function(tag) {
     404                    return rowTags.includes(tag);
     405                });
     406            }
     407        );
     408    }
     409
     410    table.draw(); // Redraw table to apply search/filter
     411
     412    //jQuery('#tagFilterContainer').slideUp(); // Hide the tag filter container
     413});
     414
     415
     416
     417
     418    });
     419
     420
     421   
    368422
    369423    </script>
     
    380434    <a class="button button-secondary" id="buttonclientsonly" href=""><?php _e( 'Show Clients only', 'wp-easy-crm' );?></a>
    381435    <a class="button button-secondary" id="buttonblackrefonly" href=""><?php _e( 'Show Refused and Blacklisted only', 'wp-easy-crm' );?></a>
     436    <style>#tagFilterContainer {
     437    padding: 10px;
     438    border: 1px solid #ccc;
     439    margin-top: 10px;
     440    }
     441    #filterbytags::after {
     442    content: '\25BC'; /* Unicode character for down-pointing triangle */
     443    }
     444
     445    #filterbytags.show-menu::after {
     446        content: '\25B2'; /* Unicode character for up-pointing triangle */
     447    }
     448
     449    </style>
     450    <a class="button button-secondary" id="filterbytags" href=""><?php _e( 'Filter by Tags', 'wp-easy-crm' );?></a>
     451    <div id="tagFilterContainer" style="display:none;">
     452    <span>Those filters will persist until the page is reloaded. Uncheck all and click 'Filter' again to show all entries.</span>
     453    <form id="tagFilterForm" style="display: flex; flex-wrap: wrap; align-items: center; padding: 10px;">
     454        <?php foreach ($allTags as $tag): ?>
     455            <label style="margin: 5px; padding: 5px; background-color: <?php echo esc_attr($tag->tagcolor); ?>; color: #ffffff; border-radius: 5px; display: flex; align-items: center;">
     456                <input type="checkbox" name="tags[]" value="<?php echo esc_attr($tag->id); ?>" style="margin-right: 5px;" />
     457                <?php echo esc_html($tag->tagtitle); ?>
     458            </label>
     459        <?php endforeach; ?>
     460        <button type="button" class="button-primary" id="applyTagFilter" style="margin-left: auto; padding: 5px 10px; cursor: pointer;"><?php _e('Filter', 'wp-easy-crm'); ?></button>
     461    </form>
     462    </div>
     463
    382464    <?php
    383465    // if general access list buttons to filter by country / accounting region
     
    457539        <th class="manage-column column-cb check-column" scope="col"><b><?php _e( 'Contacts', 'wp-easy-crm' );?></b></th>
    458540        <th class="manage-column column-cb check-column" scope="col"><b><?php _e( 'Telephone', 'wp-easy-crm' );?></b></th>
     541        <th class="manage-column column-cb check-column" scope="col"><b><?php _e( 'Tags', 'wp-easy-crm' );?></b></th>
    459542        <th class="manage-column column-cb check-column" scope="col"><b><?php _e( 'Date added', 'wp-easy-crm' );?></b></th>
    460543        <th class="manage-column column-cb check-column" scope="col"><b><?php _e( 'Region ID', 'wp-easy-crm' );?></b></th>
     
    551634    <td class="column-columnname"><?php echo esc_html($client['nombrecontacto']) ?></td>
    552635    <td class="column-columnname"><?php echo esc_html($client['telefono']) ?></td>
     636    <td class="column-columnname">
     637    <?php
     638    // Split the client's tag relations into an array of tag IDs
     639    $clientTagIds = explode(',', $client['tagsrelations']);
     640   
     641    foreach ($clientTagIds as $tagId) {
     642        // Check if the tag ID exists in the tag map
     643        if (isset($tagMap[$tagId])) {
     644            // Display the tag title in its defined color
     645            $tag = $tagMap[$tagId];
     646            echo '<span data-tagid="' . esc_attr($tag->id) . '" style="background-color: ' . esc_attr($tag->tagcolor) . '; color: #ffffff; padding: 2px 5px; border-radius: 3px; margin-right: 5px;">' . esc_html($tag->tagtitle) . '</span>';
     647        }
     648    }
     649    ?>
     650    </td>
     651
     652
    553653    <td class="column-columnname"><?php echo esc_html($client['created_at']) ?></td>
    554654    <td class="column-columnname"><?php echo esc_html($client['idaccountingregionfk']) ?></td>
Note: See TracChangeset for help on using the changeset viewer.