| @@ -8,169 +8,181 @@ | ||
| 8 | 8 | */ |
| 9 | 9 | |
| 10 | 10 | namespace MainWP\Dashboard; |
| 11 | 11 | |
| 12 | +// Exit if accessed directly. | |
| 13 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 14 | + exit; | |
| 15 | +} | |
| 16 | + | |
| 12 | 17 | /** |
| 13 | 18 | * Class MainWP_Clients |
| 14 | 19 | * |
| 15 | 20 | * Displays the Site Actions. |
| 16 | 21 | */ |
| 17 | -class MainWP_Clients { | |
| 22 | +class MainWP_Clients { // phpcs:ignore Generic.Classes.OpeningBraceSameLine.ContentAfterBrace -- NOSONAR. | |
| 18 | 23 | |
| 19 | - /** | |
| 20 | - * Method get_class_name() | |
| 21 | - * | |
| 22 | - * @return string __CLASS__ Class name. | |
| 23 | - */ | |
| 24 | - public static function get_class_name() { | |
| 25 | - return __CLASS__; | |
| 26 | - } | |
| 24 | + /** | |
| 25 | + * Method get_class_name() | |
| 26 | + * | |
| 27 | + * @return string __CLASS__ Class name. | |
| 28 | + */ | |
| 29 | + public static function get_class_name() { | |
| 30 | + return __CLASS__; | |
| 31 | + } | |
| 27 | 32 | |
| 28 | - /** | |
| 29 | - * Method render() | |
| 30 | - * | |
| 31 | - * @return mixed render_clients() | |
| 32 | - */ | |
| 33 | - public static function render() { | |
| 34 | - $clients = MainWP_DB_Client::instance()->get_wp_clients(); | |
| 35 | - self::render_clients( $clients ); | |
| 36 | - } | |
| 33 | + /** | |
| 34 | + * Method render() | |
| 35 | + * | |
| 36 | + * @return mixed render_clients() | |
| 37 | + */ | |
| 38 | + public static function render() { | |
| 39 | + $clients = MainWP_DB_Client::instance()->get_wp_clients(); | |
| 40 | + static::render_clients( $clients ); | |
| 41 | + } | |
| 37 | 42 | |
| 38 | - /** | |
| 39 | - * Render Clients Info. | |
| 40 | - * | |
| 41 | - * @param mixed $clients Clients data. | |
| 42 | - */ | |
| 43 | - private static function render_clients( $clients ) { | |
| 44 | - ?> | |
| 45 | - <div class="mainwp-widget-header"> | |
| 46 | - <h3 class="ui header handle-drag"> | |
| 47 | - <?php | |
| 48 | - /** | |
| 49 | - * Filter: mainwp_clients_widget_title | |
| 50 | - * | |
| 51 | - * Filters the Clients widget title text. | |
| 52 | - * | |
| 53 | - * @since 4.4 | |
| 54 | - */ | |
| 55 | - echo esc_html( apply_filters( 'mainwp_clients_widget_title', esc_html__( 'Clients', 'mainwp' ) ) ); | |
| 56 | - ?> | |
| 57 | - <div class="sub header"><?php esc_html_e( 'Clients information', 'mainwp' ); ?></div> | |
| 58 | - </h3> | |
| 59 | - </div> | |
| 60 | - <div id="mainwp-clients-widget" class="mainwp-scrolly-overflow"> | |
| 61 | - <?php | |
| 62 | - /** | |
| 63 | - * Actoin: mainwp_clients_widget_top | |
| 64 | - * | |
| 65 | - * Fires at the top of the Clients widget on the overview page. | |
| 66 | - * | |
| 67 | - * @param object $clients Object containing the clients info. | |
| 68 | - * | |
| 69 | - * @since 4.4 | |
| 70 | - */ | |
| 71 | - do_action( 'mainwp_clients_widget_top', $clients ); | |
| 72 | - ?> | |
| 73 | - <?php if ( $clients ) : ?> | |
| 74 | - <table class="ui table" id="mainwp-clients-widget-table"> | |
| 75 | - <thead> | |
| 76 | - <tr> | |
| 77 | - <th class="no-sort"><?php esc_html_e( '', 'mainwp' ); ?></th> | |
| 78 | - <th><?php esc_html_e( 'Client', 'mainwp' ); ?></th> | |
| 79 | - <th><?php esc_html_e( 'Primary Contact', 'mainwp' ); ?></th> | |
| 80 | - <th class="no-sort"></th> | |
| 81 | - </tr> | |
| 82 | - </thead> | |
| 83 | - <tbody> | |
| 84 | - <?php foreach ( $clients as $client ) : ?> | |
| 85 | - <?php $client_display_image = MainWP_Client_Handler::get_client_contact_image( $client ); ?> | |
| 86 | - <tr> | |
| 87 | - <td class="left aligned middle aligned"> | |
| 88 | - <a href="admin.php?page=ManageClients&client_id=<?php echo intval( $client['client_id'] ); ?>"> | |
| 89 | - <?php echo $client_display_image; //phpcs:ignore -- ok. ?> | |
| 90 | - </a> | |
| 91 | - </td> | |
| 92 | - <td class="left aligned middle aligned"> | |
| 93 | - <span><a href="admin.php?page=ManageClients&client_id=<?php echo intval( $client['client_id'] ); ?>"><?php echo esc_html( $client['name'] ); ?></a></span><br/> | |
| 94 | - <?php if ( isset( $client['client_email'] ) && '' !== $client['client_email'] ) : ?> | |
| 95 | - <span class="ui small text"><a href="mailto:<?php echo esc_attr( $client['client_email'] ); ?>"><i class="envelope icon"></i> <?php echo esc_html( $client['client_email'] ); ?></a></span><br/> | |
| 96 | - <?php endif; ?> | |
| 97 | - <?php if ( isset( $client['client_phone'] ) && '' !== $client['client_phone'] ) : ?> | |
| 98 | - <span class="ui small text"><a href="tel:<?php echo esc_attr( $client['client_phone'] ); ?>"><i class="phone alternate icon"></i> <?php echo esc_html( $client['client_phone'] ); ?></a></span> | |
| 99 | - <?php endif; ?> | |
| 100 | - </td> | |
| 101 | - <td class="left aligned middle aligned"> | |
| 102 | - <?php | |
| 103 | - $contact = false; | |
| 104 | - if ( isset( $client['primary_contact_id'] ) && '' !== $client['primary_contact_id'] ) { | |
| 105 | - $contact = MainWP_DB_Client::instance()->get_wp_client_contact_by( 'contact_id', $client['primary_contact_id'] ); | |
| 106 | - if ( $contact ) { | |
| 107 | - ?> | |
| 108 | - <span><?php echo esc_html( $contact->contact_name ); ?> <?php echo ( isset( $contact->contact_role ) && '' !== $contact->contact_role ) ? ' - ' . esc_html( $contact->contact_role ) : ''; ?></span><br/> | |
| 109 | - <?php if ( isset( $contact->contact_email ) && '' !== $contact->contact_email ) : ?> | |
| 110 | - <span class="ui small text"><a href="mailto:<?php echo esc_attr( $contact->contact_email ); ?>"><i class="envelope icon"></i> <?php echo esc_html( $contact->contact_email ); ?></a></span><br/> | |
| 111 | - <?php endif; ?> | |
| 112 | - <?php if ( isset( $contact->contact_phone ) && '' !== $contact->contact_phone ) : ?> | |
| 113 | - <span class="ui small text"><a href="tel:<?php echo esc_attr( $contact->contact_phone ); ?>"><i class="phone alternate icon"></i> <?php echo esc_html( $contact->contact_phone ); ?></a></span> | |
| 114 | - <?php endif; ?> | |
| 115 | - <?php | |
| 116 | - } | |
| 117 | - } | |
| 118 | - if ( empty( $contact ) ) { | |
| 119 | - echo esc_html__( 'No Contacts', 'mainwp' ); | |
| 120 | - } | |
| 121 | - ?> | |
| 122 | - </td> | |
| 123 | - <td> | |
| 124 | - <div class="ui right pointing dropdown icon mini basic green button mainwp-768-hide" style="z-index:999"> | |
| 125 | - <i class="ellipsis horizontal icon"></i> | |
| 126 | - <div class="menu"> | |
| 127 | - <a class="item" href="admin.php?page=ManageClients&client_id=<?php echo intval( $client['client_id'] ); ?>"><?php esc_html_e( 'View', 'mainwp' ); ?></a> | |
| 128 | - <a class="item" href="admin.php?page=ClientAddNew&client_id=<?php echo intval( $client['client_id'] ); ?>"><?php esc_html_e( 'Edit', 'mainwp' ); ?></a> | |
| 129 | - </div> | |
| 130 | - </div> | |
| 131 | - </td> | |
| 132 | - </tr> | |
| 133 | - <?php endforeach; ?> | |
| 134 | - </tbody> | |
| 135 | - </table> | |
| 136 | - <div class="ui two columns stackable grid mainwp-widget-footer"> | |
| 137 | - <div class="left aligned column"> | |
| 138 | - <a href="admin.php?page=ManageClients" class="ui button mini fluid green"><?php esc_html_e( 'Clients', 'mainwp' ); ?></a> | |
| 139 | - </div> | |
| 140 | - <div class="right aligned column"> | |
| 141 | - <a href="admin.php?page=ClientAddNew" class="ui button basic mini fluid green"><?php esc_html_e( 'New Client', 'mainwp' ); ?></a> | |
| 142 | - </div> | |
| 143 | - </div> | |
| 144 | - <script type="text/javascript"> | |
| 145 | - jQuery( document ).ready( function() { | |
| 146 | - jQuery.fn.DataTable.ext.pager.numbers_length = 4; | |
| 147 | - jQuery( '#mainwp-clients-widget-table' ).DataTable( { | |
| 148 | - "lengthMenu": [ [5, 10, 25, 50, 100, -1], [5, 10, 25, 50, 100, "All"] ], | |
| 149 | - "stateSave" : true, | |
| 150 | - "order" : [ [1, 'asc'] ], | |
| 151 | - "columnDefs": [ { | |
| 152 | - "targets": 'no-sort', | |
| 153 | - "orderable": false | |
| 154 | - } ], | |
| 155 | - } ); | |
| 156 | - } ); | |
| 157 | - </script> | |
| 158 | - <?php else : ?> | |
| 159 | - <?php MainWP_UI::render_empty_element_placeholder(); ?> | |
| 160 | - <?php endif; ?> | |
| 161 | - <?php | |
| 162 | - /** | |
| 163 | - * Action: mainwp_clients_widget_bottom | |
| 164 | - * | |
| 165 | - * Fires at the bottom of the Clients widget on the overview page. | |
| 166 | - * | |
| 167 | - * @param object $clients Object containing the child site info. | |
| 168 | - * | |
| 169 | - * @since 4.4 | |
| 170 | - */ | |
| 171 | - do_action( 'mainwp_clients_widget_bottom', $clients ); | |
| 172 | - ?> | |
| 173 | - </div> | |
| 174 | - <?php | |
| 175 | - } | |
| 43 | + /** | |
| 44 | + * Render Clients Info. | |
| 45 | + * | |
| 46 | + * @param mixed $clients Clients data. | |
| 47 | + */ | |
| 48 | + private static function render_clients( $clients ) { // phpcs:ignore -- NOSONAR - complex. | |
| 49 | + ?> | |
| 50 | + <div class="mainwp-widget-header"> | |
| 51 | + <h2 class="ui header handle-drag"> | |
| 52 | + <?php | |
| 53 | + /** | |
| 54 | + * Filter: mainwp_clients_widget_title | |
| 55 | + * | |
| 56 | + * Filters the Clients widget title text. | |
| 57 | + * | |
| 58 | + * @since 4.4 | |
| 59 | + */ | |
| 60 | + echo esc_html( apply_filters( 'mainwp_clients_widget_title', esc_html__( 'Clients', 'mainwp' ) ) ); | |
| 61 | + ?> | |
| 62 | + <div class="sub header"><?php esc_html_e( 'View and manage all clients connected to your MainWP Dashboard.', 'mainwp' ); ?></div> | |
| 63 | + </h2> | |
| 64 | + </div> | |
| 65 | + <div id="mainwp-clients-widget" class="mainwp-scrolly-overflow"> | |
| 66 | + <?php | |
| 67 | + /** | |
| 68 | + * Actoin: mainwp_clients_widget_top | |
| 69 | + * | |
| 70 | + * Fires at the top of the Clients widget on the overview page. | |
| 71 | + * | |
| 72 | + * @param object $clients Object containing the clients info. | |
| 73 | + * | |
| 74 | + * @since 4.4 | |
| 75 | + */ | |
| 76 | + do_action( 'mainwp_clients_widget_top', $clients ); | |
| 77 | + ?> | |
| 78 | + <?php if ( $clients ) : ?> | |
| 79 | + <table class="ui table" id="mainwp-clients-widget-table"> | |
| 80 | + <thead> | |
| 81 | + <tr> | |
| 82 | + <th scope="col"><?php esc_html_e( 'Client', 'mainwp' ); ?></th> | |
| 83 | + <th scope="col" class="collapsing"><?php esc_html_e( 'Primary Contact', 'mainwp' ); ?></th> | |
| 84 | + <th scope="col" class="no-sort collapsing"></th> | |
| 85 | + </tr> | |
| 86 | + </thead> | |
| 87 | + <tbody> | |
| 88 | + <?php foreach ( $clients as $client ) : ?> | |
| 89 | + <?php $client_display_image = MainWP_Client_Handler::get_client_contact_image( $client ); ?> | |
| 90 | + <tr> | |
| 91 | + <td class="left aligned middle aligned"> | |
| 92 | + <a href="admin.php?page=ManageClients&client_id=<?php echo intval( $client['client_id'] ); ?>"> | |
| 93 | + <?php echo $client_display_image; //phpcs:ignore -- ok. ?> <?php echo esc_html( $client['name'] ); ?> | |
| 94 | + </a> | |
| 95 | + <br/> | |
| 96 | + <?php if ( isset( $client['client_email'] ) && '' !== $client['client_email'] ) : ?> | |
| 97 | + <span class="ui small text"><a href="mailto:<?php echo esc_attr( $client['client_email'] ); ?>" class="ui grey text"><i class="envelope grey icon"></i> <?php echo esc_html( $client['client_email'] ); ?></a></span><br/> | |
| 98 | + <?php endif; ?> | |
| 99 | + <?php if ( isset( $client['client_phone'] ) && '' !== $client['client_phone'] ) : ?> | |
| 100 | + <span class="ui small text"><a href="tel:<?php echo esc_attr( $client['client_phone'] ); ?>" class="ui grey text"><i class="phone alternate grey icon"></i> <?php echo esc_html( $client['client_phone'] ); ?></a></span> | |
| 101 | + <?php endif; ?> | |
| 102 | + </td> | |
| 103 | + <td class="left aligned middle aligned"> | |
| 104 | + <?php | |
| 105 | + $contact = false; | |
| 106 | + if ( isset( $client['primary_contact_id'] ) && '' !== $client['primary_contact_id'] ) { | |
| 107 | + $contact = MainWP_DB_Client::instance()->get_wp_client_contact_by( 'contact_id', $client['primary_contact_id'] ); | |
| 108 | + if ( $contact ) { | |
| 109 | + ?> | |
| 110 | + <?php echo esc_html( $contact->contact_name ); ?> <?php echo ( isset( $contact->contact_role ) && '' !== $contact->contact_role ) ? ' - ' . esc_html( $contact->contact_role ) : ''; ?><br/> | |
| 111 | + <?php if ( isset( $contact->contact_email ) && '' !== $contact->contact_email ) : ?> | |
| 112 | + <span class="ui small text"><a href="mailto:<?php echo esc_attr( $contact->contact_email ); ?>" class="ui grey text"><i class="envelope grey icon"></i> <?php echo esc_html( $contact->contact_email ); ?></a></span><br/> | |
| 113 | + <?php endif; ?> | |
| 114 | + <?php if ( isset( $contact->contact_phone ) && '' !== $contact->contact_phone ) : ?> | |
| 115 | + <span class="ui small text"><a href="tel:<?php echo esc_attr( $contact->contact_phone ); ?>" class="ui grey text"><i class="phone alternate grey icon"></i> <?php echo esc_html( $contact->contact_phone ); ?></a></span> | |
| 116 | + <?php endif; ?> | |
| 117 | + <?php | |
| 118 | + } | |
| 119 | + } | |
| 120 | + if ( empty( $contact ) ) { | |
| 121 | + echo esc_html__( 'No Contacts', 'mainwp' ); | |
| 122 | + } | |
| 123 | + ?> | |
| 124 | + </td> | |
| 125 | + <td class="right aligned collapsing"> | |
| 126 | + <div class="ui right pointing dropdown mainwp-768-hide" style="z-index:999"> | |
| 127 | + <i class="ellipsis vertical icon"></i> | |
| 128 | + <div class="menu"> | |
| 129 | + <a class="item" href="admin.php?page=ManageClients&client_id=<?php echo intval( $client['client_id'] ); ?>"><?php esc_html_e( 'View', 'mainwp' ); ?></a> | |
| 130 | + <a class="item" href="admin.php?page=ClientAddNew&client_id=<?php echo intval( $client['client_id'] ); ?>"><?php esc_html_e( 'Edit', 'mainwp' ); ?></a> | |
| 131 | + </div> | |
| 132 | + </div> | |
| 133 | + </td> | |
| 134 | + </tr> | |
| 135 | + <?php endforeach; ?> | |
| 136 | + </tbody> | |
| 137 | + </table> | |
| 138 | + | |
| 139 | + <script type="text/javascript"> | |
| 140 | + jQuery( document ).ready( function() { | |
| 141 | + jQuery.fn.DataTable.ext.pager.numbers_length = 4; | |
| 142 | + jQuery( '#mainwp-clients-widget-table' ).DataTable( { | |
| 143 | + "info": false, | |
| 144 | + "layout": { | |
| 145 | + "bottom": 'paging', | |
| 146 | + "bottomStart": null, | |
| 147 | + "bottomEnd": null | |
| 148 | + }, | |
| 149 | + "lengthMenu": [ [5, 10, 25, 50, 100, -1], [5, 10, 25, 50, 100, "All"] ], | |
| 150 | + "stateSave" : true, | |
| 151 | + "order" : [ [1, 'asc'] ], | |
| 152 | + "columnDefs": [ { | |
| 153 | + "targets": 'no-sort', | |
| 154 | + "orderable": false | |
| 155 | + } ], | |
| 156 | + } ); | |
| 157 | + setTimeout(() => { | |
| 158 | + mainwp_datatable_fix_menu_overflow('#mainwp-clients-widget-table', -50, 0 ); | |
| 159 | + }, 2000 ); | |
| 160 | + } ); | |
| 161 | + </script> | |
| 162 | + <?php else : ?> | |
| 163 | + <?php MainWP_UI::render_empty_element_placeholder( __( 'No Clients yet', 'mainwp' ), __( 'Create your first client to see them listed here.', 'mainwp' ), '<em data-emoji=":bust_in_silhouette:" class="medium"></em>' ); ?> | |
| 164 | + <?php endif; ?> | |
| 165 | + <?php | |
| 166 | + /** | |
| 167 | + * Action: mainwp_clients_widget_bottom | |
| 168 | + * | |
| 169 | + * Fires at the bottom of the Clients widget on the overview page. | |
| 170 | + * | |
| 171 | + * @param object $clients Object containing the child site info. | |
| 172 | + * | |
| 173 | + * @since 4.4 | |
| 174 | + */ | |
| 175 | + do_action( 'mainwp_clients_widget_bottom', $clients ); | |
| 176 | + ?> | |
| 177 | + </div> | |
| 178 | + <div class="ui two columns stackable grid mainwp-widget-footer"> | |
| 179 | + <div class="left aligned middle aligned column"> | |
| 180 | + | |
| 181 | + </div> | |
| 182 | + <div class="right aligned middle aligned column"> | |
| 183 | + | |
| 184 | + </div> | |
| 185 | + </div> | |
| 186 | + <?php | |
| 187 | + } | |
| 176 | 188 | } |